There is nothing magical about the use or inclusion of dlmalloc in your compiled code. You can link in your own allocator implementation just as readily.
- Bruce Sent from my iPhone > On Aug 11, 2015, at 10:05 AM, awt <[email protected]> wrote: > > Thanks Floh, I was hoping to find the equivalent of Windows's _aligned_msize > which returns the exact allocated memory but I guess I can live with > malloc_usable_size for now. > >> On Thursday, August 6, 2015 at 5:59:46 AM UTC+8, Floh wrote: >> AFAIK there is no standard way to query the size you passed in to malloc() >> by the returned pointer, even malloc_usable_size is not standard. >> >> malloc_usable_size() may return a larger size, but I definitely wouldn't >> count on that this is always 4 (see here: >> http://man7.org/linux/man-pages/man3/malloc_usable_size.3.html). >> >> Some platforms or allocator libs have an msize() or _msize() function, but I >> haven't found this in the dlmalloc sources. >> >> If you absolutely need to store the size passed to alloc inside a memory >> block then I think you need to implement this on your own (allocate >> additional space for a header, store size in header, and return pointer >> after header). This will be dangerous though if you cannot guarantee that >> all alloc/free calls are properly paired and go through your own wrapper >> functions. >> >> Cheers, >> -Floh. >> >> Am Mittwoch, 5. August 2015 12:29:03 UTC+2 schrieb awt: >>> >>> Hi, >>> >>> I need to retrieve the size of a buffer that is dynamically allocated and >>> this is what I did: >>> >>> >>> size_t size = 64; >>> size_t alignment = 8; >>> memalign(alignment, size); >>> >>> size_t measuredSize = malloc_usable_size(test); >>> std::cout << "measuredSize:" << measuredSize << " size:" << size << >>> std::endl; >>> >>> However, the size returned by malloc_usable_size is always 4 more than the >>> amount that I pass in to memalign. In this case, measuredSize will be 68. I >>> tried using malloc and the result is the same. >>> >>> Is there a way to get the size that I pass into memalign or can I always >>> assume that malloc_usable_size will always report a higher size of 4 bytes? > > -- > You received this message because you are subscribed to the Google Groups > "emscripten-discuss" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "emscripten-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
