473,320 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

fixed type allocator - Intel IPP

STL allocators are templates so that when you write one you are obliged
to make it work with any type. However, the Intel IPP library that we
use has memory aligned allocators for each of 15 different types. For
example an 8 bit unsigned array is allocated with ippsMalloc_8u(size).

So I want to create memory aligned allocators for use with the STL (in
particular the vector container) that is fast (due to alignment), and
pointer compatible with other IPP library functions.

Is there any way to create an allocator of a fixed type? Right now it
seems the only way it can work is:

vector<Ipp8u, myAllocIpp8u<Ipp8u>> ipp8uVector;

But A) its redundant and liable to lead to allocator mismatch, and B)
leaves the internal rebind typecast undefined.

I'd prefer either:

vector<Ipp8u, myAllocIpp8u> ipp8uVector; // fixed type allocator

or

vector<Ipp8u, myAlloc<Ipp8u>> ipp8uVector; // allocator that can
// switch by type

But I don't see how either of these are possible.

Thanks,
j

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Jul 23 '05 #1
2 3423
On Sat, 28 May 2005 15:03:23 +0400, Joshua Kolden
<jo****@koldnhostile.com> wrote:
STL allocators are templates so that when you write one you are obliged
to make it work with any type. However, the Intel IPP library that we
use has memory aligned allocators for each of 15 different types. For
example an 8 bit unsigned array is allocated with ippsMalloc_8u(size).

So I want to create memory aligned allocators for use with the STL (in
particular the vector container) that is fast (due to alignment), and
pointer compatible with other IPP library functions.
Please note, that std::vector<> stores its elements in an array. Elements
in arrays in C and C++ are stored contiguously with no padding between
them, which means that if you force the alignment of an array to be more
than that of element type's natural one, you only align so the first
element of the array, all other array elements remain aligned with their
natural alignment.

Also, no matter what alignment, std::vector<> may use or may not use
standard algorithms in its implementation, which means that you'd probably
have to specialize algorithms like std::copy, std::uninitialized_copy,
etc.., to take advantage of IPP library functions.

Not sure I understand "pointer compatible" issue.
Is there any way to create an allocator of a fixed type? Right now it
seems the only way it can work is:

vector<Ipp8u, myAllocIpp8u<Ipp8u>> ipp8uVector;

But A) its redundant and liable to lead to allocator mismatch, and B)
leaves the internal rebind typecast undefined.

I'd prefer either:

vector<Ipp8u, myAllocIpp8u> ipp8uVector; // fixed type allocator

or

vector<Ipp8u, myAlloc<Ipp8u>> ipp8uVector; // allocator that can
// switch by type


Create your own allocator which kicks in for your types and uses stock
std::allocator implementation for all other type. Something along these
lines:

template<class T = void>
struct my_alloc;

template<class T>
struct my_alloc_impl
{
template<class U>
struct rebind { typedef my_alloc<U> other; };

// std::allocator interface implementation
};

template<class T>
struct my_alloc : std::allocator<T>
{
// override std::allocator<T>'s rebind
template<class U>
struct rebind { typedef my_alloc<U> other; };
};

// specialize it for your types
template<> struct my_alloc<whatever> : my_alloc_impl<whatever> {};
// ...

--
Maxim Yegorushkin

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Jul 23 '05 #2
You can create an allocator that switches by type with template
specialization:

template <typename T>
class myAlloc {
// Generic allocator
};

template <>
class myAlloc<Ipp8u> {
// Specialized for Ipp8u
};

You can also use fixed type allocators provided you define them with
the same operations as are expected. For example, rebind is expected to
be a template class with a nested type 'other'. You can effectively
make that a noop without breaking the interface by saying:

class myAllocIpp8u {
public:
// ...
template <typename T> struct rebind { typedef myAllocIpp8u other; };
// ...
};
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: DarkSpy | last post by:
g++ 3.2.x and g++ 3.3 have this bug: class A{}; main() { sizeof(A()); } got error message: ISO C++ forbids applying `sizeof' to a function type
5
by: Scott Brady Drummonds | last post by:
Hi, everyone, A coworker and I have been pondering a memory allocation problem that we're having with a very large process. Our joint research has led us to the conclusion that we may have to...
3
by: Min-Koo Seo | last post by:
Hello. I am reading Effective C++ by Scott Myers. In item 10, there is a question for readers: writing generalized fixed size memory allocator. I tried to solve the problem, but I couldn't. To...
13
by: Thomas J. Clancy | last post by:
I was just wondering. After all these years of working on Visual C++, why hasn't Microsoft yet seen fit to fully implement the template portion of the C++ standard when so many other vendors,...
7
by: Alden Pierre | last post by:
Hello, I'm trying to create my own user define container, but I'm having a little hard time figuring out why is my class considered undefined by my compiler. Here is the following code. //...
3
by: rosun82 | last post by:
Recently I am trying to develop a C++ program dealing with large scale DAGs (about 6,000,000 nodes and 50,000,000 edges), and I find a very serious problem here. In the program, the node and edges...
3
by: Martin T. | last post by:
Hello. I tried to overload the operator<< for implicit printing of wchar_t string on a char stream. Normally using it on a ostream will succeed as std::operator<<<std::char_traits<char> will...
6
by: Paavo Helde | last post by:
Juha Nieminen <nospam@thanks.invalidwrote in news:47f91b3c$0$8161 $4f793bc4@news.tdc.fi: I would guess that most speedup comes from the fact that the general allocator is thread-safe and yours...
16
by: PeterAPIIT | last post by:
Hello all C++ expert programmer, i have wrote partial general allocator for my container. After reading standard C++ library and code guru article, i have several questions. 1. Why...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.