The issue is what is demanded by the problem. Let me spell it out and maybe you can suggest an alternate approach.
My list processor allocates (new) and deallocates (delete) from a private pool of cells, called the AVSL. There are three sources of cell creation:
- From AVSL.
- From the stack.
- From the heap.
Cells created from either the stack or the heap can not be put onto a list or deleted and put in the AVSL, or be a list header containing data. Further, a user with a stale pointer to a deallocated cell, now on the AVSL, must be prevented from using the cell. I handle these conditions by (1) making cell links private, and (2) posting data to the cell links which allow me to distingush the three cases., and to throw an exception when they are found.
Without the ability to post 'special' link values during cell creation (new) and deletion I know of no way that I can detect how the cell was created and limit the use of the cells. The effect is to create an opportunity to corrupt lists and the AVSL in such a way that random errors will occor.
There was a suggestion on another forum that contructors (misconstructors?) be made private, and that factories be created to take care of the issue. That can be a lot of work. On the other hand, the easiest way to mark the cells appropriately is to do so during cell creation, but this requires that the automatic initialzing of objects during constructor use be disabled.
The software is some 16,000 lines long with an additional 50,000 to 60,000 lines of comments. It can be viewed at https://www.gnu.org/software/gslip/. The software was successfully tested in about 2014 using gcc.
thanks