Community
cancel
Showing results for 
Search instead for 
Did you mean: 
zach_turner
Beginner
63 Views

size of an allocation

supposing that I issue a request to any of TBB's allocators (cache_aligned, scalable, scalable_aligned), is there any reasonable way for me to go about obtaining a number N such that N >= number of bytes requested, and N <= number of bytes actually allocated? I don't think that writing a wrapper around these that keep an internal hash table is reasonable because it's going to require locking, and I'm sure TBB internally knows the size of all allocations anyway.
0 Kudos
4 Replies
RafSchietekat
Black Belt
63 Views

I'm not sure I understand your question, but there is a predictable function from request size to allocation size (for the smaller request sizes up to about 8 kB anyway), and TBB then treats the request as a request for that allocation size, i.e., it forgets the exact number of bytes originally requested, because it would be too much overhead to remember that.

(Added) That's for scalable_malloc, anyway.

(Corrected 2009-07-24) scalable_malloc, not scalable_alloc.

zach_turner
Beginner
63 Views

Quoting - Raf Schietekat

I'm not sure I understand your question, but there is a predictable function from request size to allocation size (for the smaller request sizes up to about 8 kB anyway), and TBB then treats the request as a request for that allocation size, i.e., it forgets the exact number of bytes originally requested, because it would be too much overhead to remember that.

(Added) That's for scalable_alloc, anyway.


What I was looking for is a way to write the following function using whatever means necessary, even if it relies on behavior of TBB that is technically an implementation detail and not guaranteed to work in future versions of the library:

//PRECONDITIONS:
// - 'buf' is a pointer previously returned from scalable_malloc(alloc_size)
// - scalable_free(buf) has not yet been called.
size_t scalable_malloc_allocation_size(void* buf)
{
// return some number N such that N >= alloc_size && N <= bytes_actually_reserved_by_scalable_malloc
}

So in other words, at some point long after the request to scalable_malloc() has been issued and I've lost the information about how many bytes were requested, I want to determine how many bytes can safely be written into a buffer that I know was returned by a previous call to scalable_malloc

similarly for scalable_aligned_malloc and cache_aligned_allocator.
RafSchietekat
Black Belt
63 Views

For scalable_malloc() memory, examine src/tbbmalloc/MemoryAllocator.cpp, and specifically scalable_free(), which needs to locate a Block, which has an objectSize field, which is exactly what you want, unless the allocation was delegated to malloc() because the requested size was more than about 8 kBscalable_msize() will serve you this information on a platter. (I have not previously looked at the others yet, but I suppose it's something similar.)

(Amended 2009-07-24) See modifications.
Alexey_K_Intel3
Employee
63 Views

Quoting - Raf Schietekat
For scalable_malloc() memory, examine src/tbbmalloc/MemoryAllocator.cpp, and scalable_msize() will serve you this information on a platter.

We have added scalable_msize just recently. As Raf corectly said, it does exactly what you want. In the last developer update, scalable_msize is ready to use on Windows; for Linux and Mac, one have to add an entry into .def files for these platforms.Seems we simply overlooked that it is useful on all platforms (and not only as the replacement for MS-specific _msize).
Reply