digitalmars.D.learn - How can I get the total memory size of a Jagged Array
- seany (10/10) Nov 13 2023 Hello
- Alexandru Ermicioi (3/6) Nov 14 2023 Perhaps, use length property of string. It should tell you length
- novice2 (3/3) Nov 14 2023 may be std.string.representation() may help?
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
Nov 13 2023
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 youPerhaps, use length property of string. It should tell you length of a string and then you multiply it by size of char.
Nov 14 2023
may be std.string.representation() may help? https://dlang.org/phobos/std_string.html#.representation byteSize = representation(myString).length;
Nov 14 2023