Thread overview
How can I get the total memory size of a Jagged Array
Nov 13
seany
Nov 14
novice2
November 13

Hello

Let's assume, that we have a string array : string[] sa;

I fill up the array with random strings with random lengths.

I want to know how much space it occupies in memory.

I could go over the string array using a for loop, then another loop for each character, and then sum up char.sizeof. But this would be very slow and inefficient.

Is there a better way? I want a method that works for every variable type including classes and objects.

Thank you

November 14

On Monday, 13 November 2023 at 14:15:31 UTC, seany wrote:

>

Is there a better way? I want a method that works for every variable type including classes and objects.

Thank you

Perhaps, use length property of string. It should tell you length of a string and then you multiply it by size of char.

November 14

may be std.string.representation() may help?
https://dlang.org/phobos/std_string.html#.representation

byteSize = representation(myString).length;