I currently allocate my memory for arrays using the MS specific mm_malloc. I align the memory, as I’m doing some heavy duty math and the vectorization takes advantage of the alignment. I was wondering if anyone knows how to overload the new operator to do the same thing, as I feel dirty malloc’ing everywhere (and would eventually like to also compile on Linux)? Thanks for any help
I currently allocate my memory for arrays using the MS specific mm_malloc. I align
Share
First of all, it’s important to note that
newanddeletecan be overloaded either globally, or just for a single class. Both cases are shown in this article. Also important to note is that if you overloadnewyou almost certainly also want to overloaddelete.There are a few important notes about
operator newandoperator delete:operator new[]andoperator delete[], so don’t forget about overloading those.operator newand its brethren, so make sure to override those.In Effective C++, item 8, Scott Meyers includes some pseudocodish examples:
For more information, I’d definitely pick up Effective C++.