Re: Get size of mem to free by free

2016-08-05 Thread Ali Çehreli via Digitalmars-d-learn
On 08/05/2016 03:49 PM, H.Loom wrote: On Friday, 5 August 2016 at 21:25:41 UTC, Ali Çehreli wrote: malloc stores the allocation size and other information right before the pointer that it returns. TIL. Is it guaranteed for any malloc implementation ? I'm a bit surpised to read that. I thought

Re: Get size of mem to free by free

2016-08-05 Thread H.Loom via Digitalmars-d-learn
On Friday, 5 August 2016 at 21:25:41 UTC, Ali Çehreli wrote: malloc stores the allocation size and other information right before the pointer that it returns. TIL. Is it guaranteed for any malloc implementation ? I'm a bit surpised to read that. I thought these kind of trick was only used for

Re: Get size of mem to free by free

2016-08-05 Thread Ali Çehreli via Digitalmars-d-learn
On 08/05/2016 12:55 PM, Mark J Twain wrote: I use malloc to allocate some memory, then free it later. For monitoring purposes, I would like to know how much is free'ed by free by just knowing the object. Or, rather, given a ptr allocated by malloc, bet the block size it allocated from the ptr alo

Re: Get size of mem to free by free

2016-08-05 Thread H.Loom via Digitalmars-d-learn
On Friday, 5 August 2016 at 21:07:02 UTC, H.Loom wrote: On Friday, 5 August 2016 at 20:54:59 UTC, Mark "J" Twain wrote: On Friday, 5 August 2016 at 20:43:12 UTC, H.Loom wrote: On Friday, 5 August 2016 at 19:55:22 UTC, Mark "J" Twain wrote: [...] You can wrap the C memory allocations function

Re: Get size of mem to free by free

2016-08-05 Thread H.Loom via Digitalmars-d-learn
On Friday, 5 August 2016 at 20:54:59 UTC, Mark "J" Twain wrote: On Friday, 5 August 2016 at 20:43:12 UTC, H.Loom wrote: On Friday, 5 August 2016 at 19:55:22 UTC, Mark "J" Twain wrote: [...] You can wrap the C memory allocations functions with a version identifier, e.g version(stat) {

Re: Get size of mem to free by free

2016-08-05 Thread Mark J Twain via Digitalmars-d-learn
On Friday, 5 August 2016 at 20:43:12 UTC, H.Loom wrote: On Friday, 5 August 2016 at 19:55:22 UTC, Mark "J" Twain wrote: [...] You can wrap the C memory allocations functions with a version identifier, e.g version(stat) { __gshared size_t[size_t] sizes; } version(stat) { auto mallo

Re: Get size of mem to free by free

2016-08-05 Thread H.Loom via Digitalmars-d-learn
On Friday, 5 August 2016 at 19:55:22 UTC, Mark "J" Twain wrote: I use malloc to allocate some memory, then free it later. For monitoring purposes, I would like to know how much is free'ed by free by just knowing the object. Or, rather, given a ptr allocated by malloc, bet the block size it allo

Get size of mem to free by free

2016-08-05 Thread Mark J Twain via Digitalmars-d-learn
I use malloc to allocate some memory, then free it later. For monitoring purposes, I would like to know how much is free'ed by free by just knowing the object. Or, rather, given a ptr allocated by malloc, bet the block size it allocated from the ptr alone. Some C compilers have special intrin