deallocate allocated memory

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Jul 2009
Posts: 57
Reputation: atch is an unknown quantity at this point 
Solved Threads: 0
atch atch is offline Offline
Junior Poster in Training

deallocate allocated memory

 
0
  #1
Oct 2nd, 2009
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:
  1. template<typename T>
  2. void Allocator<T>::deallocate(pointer p, size_type n)
  3. {
  4. free(p);
  5. }
I have no idea for what I should use this (size_type) parameter.
Looking forward to your reply.
Thank you.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 681
Reputation: Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of Tom Gunn has much to be proud of 
Solved Threads: 133
Tom Gunn's Avatar
Tom Gunn Tom Gunn is offline Offline
Practically a Master Poster

Re: deallocate allocated memory

 
0
  #2
Oct 2nd, 2009
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.
-Tommy (For Great Justice!) Gunn
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 57
Reputation: atch is an unknown quantity at this point 
Solved Threads: 0
atch atch is offline Offline
Junior Poster in Training

Re: deallocate allocated memory

 
0
  #3
Oct 2nd, 2009
Tom Gunn - Thanks a lot!!! Now I can relax and watch some tv. Once again - thanks
Reply With Quote Quick reply to this message  
Reply

Tags
memory

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 644 | Replies: 2
Thread Tools Search this Thread



Tag cloud for memory
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC