serializing heap memory.

C

CoDE++

I want to create memory dynamically on heap but somehow want to keep
the pointers to the heap memory allocated in the contiguous stack
memory so as to traverse heap memory in an ordered fashion by
traversing stack memory and accessing the pointers stored there. Can
his be be done somehow? A small piece of code will be of a great help.
 
S

Salt_Peter

I want to create memory dynamically on heap but somehow want to keep
the pointers to the heap memory allocated in the contiguous stack
memory so as to traverse heap memory in an ordered fashion by
traversing stack memory and accessing the pointers stored there. Can
his be be done somehow? A small piece of code will be of a great help.

It can be done in so many ways that one would require a book to cover
basic details and various options available. Assuming some user type A
you could perhaps consider a std::vector<A*> since contiguous memory
was specified as a requirement.

Typically, a stack is a LIFO (Last in first Out) container. The idea
is that one pops and pushes elements from one end only. Stacks aren't
meant to be -traversed- as you might do with a primitive array.

You may want to consider a std::deque if you need a stack with 2 ends
but organized in blocks or in the case -ordered fashion- means some
specific sequenced arrangement, a sequenced container like a std::set
might do (or std::multiset if the allocations are organized by
priorities).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,076
Latest member
OrderKetoBeez

Latest Threads

Top