Thread: How to guarantee alignment with malloc and or new?

  1. #16
    Alessio Stella
    Join Date
    May 2008
    Location
    Italy, Bologna
    Posts
    251
    Quote Originally Posted by matsp View Post
    There are two ways to achieve aligned new - placement new with a pre-aligned buffer and implement a class-specific new/delete pair. In both cases, you will be allocating memory separately, but in the class-specific new/delete you can hide the fact from a user of the classs.

    --
    Mats
    could you give some example code?

  2. #17
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by mynickmynick View Post
    could you give some example code?
    http://www.bearcave.com/software/c++_mem.html is the first link on "Overloading new". Stroustrup mentions in-class implementation of new/delete on pages 422-423 (and a few other places, but that's less meaningful).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed