- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am trying to provide my allocator for the tbb::concurrent_unordered_map to do a custom action on the value, but the destroy method of the allocator receives a pointer of the flist_iterator type which has the protected my_node_ptr variable. So I can not access it.
What is the right way to provide a custom action on the destroy? (besides modifying the tbb source code)
Note: the value is a pointer and I can not wrap it into a struct as value, I need to have my allocator.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello, Andrew,
The simplest thing I could suggest is to walk the list before destruction, freeing the pointed-to memory. I think that is what you'd have to do if it was a std::vector of pointers, or other standard library container.
Do I understand your description right? You are asking if there is a way to insert pointers you have allocated into a concurrent_unordered_map, and when the map is destroyed, have all the pointers you inserted freed first by the map destructor?
Regards,
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Chris,
Yes, when the clear method is called, I need to deallocate all values. And I am trying to avoid a redundant walk since the concurrent_unordered_map goes through all values anyway. I have a lot of stuff in memory so I am trying to make it more efficient.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Here is how to provide a custom action on the destroy:
[cpp]template<typename T>
struct myalloc: tbb::tbb_allocator<T> {
template<typename U>
struct rebind {
typedef tbb::tbb_allocator<U>other; // OK
// typedef myalloc<U> other; // ERROR
};
myalloc() throw() {}
myalloc(const myalloc&) throw() {}
template<typename U> myalloc(const myalloc<U>&) throw() {}
void destroy(pointer p) {
delete (**p).second; // custom action
p->~value_type();
}
};[cpp]

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page