Limit Heap size
-
Hello,
I'm looking for a way to limit the heap size of an c++ project. I use the Qt Creator, so i wonder if there is maybe an option that can set the maximum size of the heap, or maybe there is a c++ command that can do it.
So why do i need it:
I want to force other developers to use the delete command, after they used the new command to allocate an object on the heap.So it's about an custom list class. The heap should has just enought space to store about 5 list elements. If you want to add an other element you need to delete one of the entry and NOT just delete the pointer of the last next pointer to decrease the list size.
-
Hi,
No need to make it difficult! Make sure they setup the QObject parent correctly. QObject uses a lightweight reference counter. When nothing (pointer is deleted) is referencing to the QObject it will get deleted for you!
So it add a bit of C++ extra to it. -
That's an nice work around. But the project should teach programming, so i wanted an example where it is necessary to delete the created objects.
My idea was to limit the heap, so that only about 5 elements can be reserved. if you want an other element you need to delete an existing one first.