String in bytes [delphi]

I need to keep my data in memory. My data like my data is a string. I want to minimize memory usage. I think I need to change the string to byte. I'm right? If I convert the string to byte, does that mean I need to convert the string to TMemoryStream?

+3
source share
3 answers

If you really want to convert it, this code will be executed

var
  BinarySize: Integer;
  InputString: string;
  StringAsBytes: array of Byte;
begin
  BinarySize := (Length(InputString) + 1) * SizeOf(Char);
  SetLength(StringAsBytes, BinarySize);
  Move(InputString[1], StringAsBytes[0], BinarySize);

But as already mentioned, this will not save you. Their number will be almost the same. You will not get anything from this. If you have many lines, use a different approach. Like something from this list of options:

  • Use a dictionary and keep only one line after
  • . - . .
  • , .
  • , - , . .

, .

, ( ), Suffix Trie B-Tree . . , .

, , , , , . 22 .

+5

, , ?

2000 10 - 20000 .

. . . , , .

, . , 20000 -, , .. , -, , .

+1

Make your storage type tutf8string. It can simply be assigned from tunicodestring, and the conversion should be safe.

0
source

Source: https://habr.com/ru/post/1782864/


All Articles