In C++, there exists an inplace-new operator to create an object using preallocated memory. Is there an equivalent option in Delphi?
1 Answer
There is no direct equivalent (that I know of), but you can achieve much the same effect (controlling how and where memory for an object type is allocated) by overriding the NewInstance class function in your custom class and providing an implementation, which provides the space for the new instance from a custom heap pool.
2 Comments
cytrinox
Well, the idea was a flexible way to create any class on memory already allocated by an external allocator (which can call a callback function for destruction). NewInstace overrides can't provide this. But if there is no other chance I'll try it.
David Heffernan
NewInstance can do that but it requires a rather messy way to get the address of the pre allocated memory to NewInstance.