Hi,
I'm trying to implement my own allocator using malloc and free. One thing what interests me is that in declaration of deallocate in addition to pointer we have also parameter size which suppose to be size of elements allocated with allocate but having implemented my deallocate as this:

template<typename T>
void Allocator<T>::deallocate(pointer p, size_type n)
{
     free(p);
}

I have no idea for what I should use this (size_type) parameter.
Looking forward to your reply.
Thank you.

I have no idea for what I should use this (size_type) parameter.

If your allocator does not need it, do not worry about it. The allocator interface was designed to be generic, and some allocators will need that information to manage the memory. For example, moving blocks from a 'used' pool to a 'free' pool means knowing how many blocks to move. Or more simply, the size could be used for debug information.

Tom Gunn - Thanks a lot!!! Now I can relax and watch some tv. Once again - thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.