3

In C++, there exists an inplace-new operator to create an object using preallocated memory. Is there an equivalent option in Delphi?

1

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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.
NewInstance can do that but it requires a rather messy way to get the address of the pre allocated memory to NewInstance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.