Discussion:
HeapCreate - How to quick-and-easy drop all of its contents
(too old to reply)
R.Wieser
2018-05-08 09:39:33 UTC
Permalink
Hello All

I'm in the need of storing some random-sized data items, and thought it
would be handy to use a memory heap for it (HeapCreate), as I could than,
so I assumed, afterwards just tell to discard its contents (instead of
deleting the items one-by-one ).

Alas, when I (just now) was looking for such a "drop everything you've got
stored" function I was unable to find it.

Does anyone have an idea ? Is it maybe a just a case of providing the
right arguments to one of the available functions ?

Regards,
Rudy Wieser
David Lowndes
2018-05-08 13:28:29 UTC
Permalink
Post by R.Wieser
Alas, when I (just now) was looking for such a "drop everything you've got
stored" function I was unable to find it.
HeapDestroy maybe?
https://msdn.microsoft.com/en-us/library/windows/desktop/aa366700(v=vs.85).aspx

Dave
R.Wieser
2018-05-08 14:05:25 UTC
Permalink
David,
Post by David Lowndes
HeapDestroy maybe?
I found that one too, but when I read it it seemed to be the counterpart to
HeapCreate.

"Processes can call HeapDestroy without first calling the HeapFree function
to free memory allocated from the heap."

In other words, although it releases all allocations on/in the heap, it
releases the heap itself too. And that last bit isn't quite what I'm after
...

(I did browse thru all MSDN descriptions for the HeapXxxx functions as
available in Kernel32)

Regards,
Rudy Wieser
JJ
2018-05-08 22:15:46 UTC
Permalink
Post by R.Wieser
In other words, although it releases all allocations on/in the heap, it
releases the heap itself too. And that last bit isn't quite what I'm after
....
Unless the heap handle has been passed to other application/module/component
which you don't have any control of, I don't see why getting a new heap
handle is a problem.
JJ
2018-05-08 22:14:00 UTC
Permalink
Post by R.Wieser
Hello All
I'm in the need of storing some random-sized data items, and thought it
would be handy to use a memory heap for it (HeapCreate), as I could than,
so I assumed, afterwards just tell to discard its contents (instead of
deleting the items one-by-one ).
Alas, when I (just now) was looking for such a "drop everything you've got
stored" function I was unable to find it.
There isn't any, unfortunately. It would be nice if there's a "HeapReset"
function function, tho.
Post by R.Wieser
Does anyone have an idea ? Is it maybe a just a case of providing the
right arguments to one of the available functions ?
If Heap is required, the only way I could think of is to unallocate each of
them manually.

Otherwise, I'd roll my own memory partition manager - just for the sake of
having a reset functionality.
R.Wieser
2018-05-09 06:36:02 UTC
Permalink
JJ,
Post by JJ
There isn't any, unfortunately. It would be nice if there's a
"HeapReset" function function, tho.
For some reason or another I thought that such a function existed. But it
looks like I must have mis-interpreted something I read a while ago.
Post by JJ
If Heap is required, the only way I could think of is to unallocate
each of them manually.
Another could be to destroy-and-recreate. But although it would do what I
want from it I can't say I like the way its works ...

And alas, that (unallocating one-by-one) means that using a heap seems to
have nothing over any of the other available methods (Local/GlobalAlloc,
BStr).
Post by JJ
Otherwise, I'd roll my own memory partition manager - just for the sake
of having a reset functionality.
:-) I started with (a minimal) something like that, and want to get rid of
it.

Regards,
Rudy Wieser






But as all other methods need the exact same, and several of those do not
need to be told which heap to
Post by JJ
Post by R.Wieser
Hello All
I'm in the need of storing some random-sized data items, and thought it
would be handy to use a memory heap for it (HeapCreate), as I could than,
so I assumed, afterwards just tell to discard its contents (instead of
deleting the items one-by-one ).
Alas, when I (just now) was looking for such a "drop everything you've got
stored" function I was unable to find it.
There isn't any, unfortunately. It would be nice if there's a "HeapReset"
function function, tho.
Post by R.Wieser
Does anyone have an idea ? Is it maybe a just a case of providing the
right arguments to one of the available functions ?
If Heap is required, the only way I could think of is to unallocate each of
them manually.
Otherwise, I'd roll my own memory partition manager - just for the sake of
having a reset functionality.
JJ
2018-05-09 12:37:42 UTC
Permalink
Post by R.Wieser
Another could be to destroy-and-recreate. But although it would do what I
want from it I can't say I like the way its works ...
Yes, it's like having to delete an existing file then recreate it, in order
to change its data.
Post by R.Wieser
And alas, that (unallocating one-by-one) means that using a heap seems to
have nothing over any of the other available methods (Local/GlobalAlloc,
BStr).
BStr? Is that even a function?
R.Wieser
2018-05-09 14:39:13 UTC
Permalink
JJ,
Post by JJ
BStr? Is that even a function?
Nope. Its just that I could not remember the function name at the moment I
was writing it. Though its what the contents are called. The function
involved is SysAllocString (oleaut32).

Regards,
Rudy Wieser

Loading...