Re: Print RAM used by arrays

2018-12-14 Thread Giovanni Di Maria via Digitalmars-d-learn

Thank you very much for your
precious informations.
Now i will try.
Thank you!!!
Giovanni



Re: Print RAM used by arrays

2018-12-13 Thread Steven Schveighoffer via Digitalmars-d-learn

On 12/13/18 4:32 PM, Giovanni Di Maria wrote:

Hi.
How can I know the amount of RAM allocated by a vector?

For example:

string[8][1000] array;
for(int i=0;i<1000;i++) {
array[i]=["","","","","","","",""];
}

how can I know the amount of bytes of above matrix?


array.sizeof. BUT I would caution that you have used fixed-sized arrays 
so they will NOT be allocated on the heap, but rather on the stack (or 
thread-local storage if it's a global).


For a variable-sized array, such as string[8][], the .sizeof property is 
always going to be 2 words.


For that case, you need to use the GC to ask for the block size:

writeln(GC.sizeof(array.ptr));


Can I clean the memory ofter his use, without use GC?


It depends on where you put it. But generally D does not give back any 
memory to the OS unless asked to do so.


But maybe that's not your question?

-Steve