I need to process dozens of Gigabytes data in a single binary. Each entry in the data file has a variable length.
So the file looks like this:
<len1><data1><len2><data2>..........<lenN><dataN>
The data contains an integer, pointer, double value, etc.
I found that python cannot handle this situation. No problem if I read the entire file in memory. It is fast. But it seems that the package is structnot suitable for performance. It is almost stuck in decompressing bytes.
struct
Any help is appreciated.
Thanks.
struct array, , , , . buffer, mmap, ctypes, , . , Cython-encoded , ( C, ++, Fortran,...), .
array
, , - , , ? , "", , ? , (, ), , "", , , ? ( array - , array !). , " "? Etc ..
(, , , , , 64- - !), , , ! -).
array, , array.fromfile. :
array.fromfile
.
. try-except.
:
class foo(Structure): _fields_ = [("myint", c_uint32)]
bar = foo()
,
block = file.read(sizeof(bar)) memmove(addressof(bar), block, sizeof(bar))
lenN, . . , pack() unpack(), , - .
bitstring.
struct bytearray, Bits , .
from bitstring import Bits s = Bits(filename='your_file') while s.bytepos != s.length: # Read a byte and interpret as an unsigned integer length = s.read('uint:8') # Read 'length' bytes and convert to a Python string data = s.read(length*8).bytes # Now do whatever you want with the data
, , .
, , , , , , s[-800:] 100 .
s[-800:]
, sqlite3 .
import sqlite3 sqlite3.Connection(":memory:")
sql .
, generators ( ) iterators ( ).
PyTables - HDF5, , , :
It works more or less like a hierarchical database, where you can store several tables inside columns. Look at this.
Source: https://habr.com/ru/post/1715325/More articles:Left Join all rows on the left that do not match the Where clause - sqlWhy regex "[^ <] * <\\?" exponential time when the text does not have a "<"? - regexhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1715322/how-to-move-private-fields-to-the-top-of-the-class-with-resharper&usg=ALkJrhiY49UVG0hKuOm_LTMsd8HOg8GqtwXSLT Custom Sort - sortingClassic ASP in 64-bit mode and .NET COM DLL - .netFormatting numbers is right-aligned while keeping the currency symbol left-aligned - asp.netReporting Services 2008 on Sql Server 2005 - sql-serverhow to send SMS / E-mail from the application - emailHow to change onmouseover event using javascript? - javascriptcall the boulder validator in the MultiActionController ModelAndView method ... maybe? as? - javaAll Articles