11 hours ago
(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.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.
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)for very big mpos?sql$ = Space$(mpos): _MemGet m, m.OFFSET, sql$
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)With very big strings this is also expensivesql$ = Left$(sql$, mpos - 1) + Mid$(sql$, mpos + 1)
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.