Android Question Maximum buffer length of a string

Wosl

Member
Thank you Erel,

In my tests yesterday i came to the same conclusion. My string data is of variable length depending on the app situation and therefore, some times I run out of memory in different situations. So, the remaining system memory is the limit of the character string.

I need such a long string to output a calculated result into a external file (on SD card). My solution is to slice the string in handy buckets and use the append mode to get the file stored completely. This works now with your help:
https://www.b4x.com/android/forum/threads/append-text-with-externalstorage-class.165231/

To get around the process memory issue, I need now a method to read text in buckets into a string to process data step by step, too. I'm using the ExternalStorage method to write the file (append) step by step, but how can I read in the data from the external file with ExternalStorage step by step?

Best Regards
Wolf

PS: I'm not sure if I need to launch a new thread for this question ...
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Longtime User
In the late seventies, when available memory space was very limited and expensive, the solution to your challenge was to first read a line byte by byte up to an end marker (for example CR or CRLF) via Random Access File and then to retrieve a block from the offset value to the found end marker as block length. Then you increased the offset value by the length of the read block to read in the next block from the new offset value.

The advantage of that method is that you do not need memory-intensive string builder functionality and you also do not have to deal with the intensive and lengthy garbage routine to free up the no longer used string space in memory. Perhaps that is why the conversion could be faster than with a string builder solution.
 
Upvote 0

emexes

Expert
Licensed User
My solution is to slice the string in handy buckets

How is the string (or file) sliced?

Known fixed length records? Perhaps according to the data, eg record type A are 17 bytes long, record type B are 23 bytes long.

Variable length, specified by a count preceding the string data? Like TurboPascal.

Some kind of terminator byte (or bytes)? Like C with 0-byte, or ASCII text files with CR or LF or a combination thereof.
 
Upvote 0

emexes

Expert
Licensed User
How is the string (or file) sliced?

Or like a PDF, where there is an index is at the end of the file, that is an array of pointers to the starts of the chunks (buckets).

Putting the index at the end of the file means that you can write the file in a single pass, even if you don't know how many chunks (buckets) will be in the file = how much space you would need to leave at the start of the file for the index.
 
Upvote 0
Top