Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Most efficient way to build a big variable length string?
#5
(Yesterday, 09:37 AM)mdijkens Wrote: I need to build a huge variable length string (>1GB) in memory before calling a function or writing to a file.
I already found out I can most efficiently build it up in a _MEM block.
But what is the best way to move that in the end to a variable string without copying and doubling the memory used.
So basically I am looking to a more efficient way to do:
Code: (Select All)
sql$ = Space$(mpos): _MemGet m, m.OFFSET, sql$
for very big mpos?
Is that even possible?

related to this, what is the most efficient coding to work with a big string where you have to remove a lot of pieces out without doing something like:
Code: (Select All)
sql$ = Left$(sql$, mpos - 1) + Mid$(sql$, mpos + 1)
With very big strings this is also expensive
Just to save you some time and frustration, you cannot create a 1GB variable-length string. Beyond just the general problems (String's get copied a decent amount), there are bugs regarding the handling of extremely large strings like this that will crash your program. A 1GB fixed-length string might work because it's allocated differently from a variable-length one, but I wouldn't bother and you're likely to run into similar issues with it. _MEM is the only way to deal with a piece of data that large.

Like Steve mentioned you're much better off just splitting it up into smaller parts. Unfortunately we don't have a `_MemPut` that will let you write the _MEM directly to a file, so a copy is going to be necessary.
Reply


Messages In This Thread
RE: Most efficient way to build a big variable length string? - by DSMan195276 - 11 hours ago



Users browsing this thread: 10 Guest(s)