>> I am trying to understand what might be a few major and general >>reasons why programmers might have pointers to global and stack data as
>>compared to pointers to heap which are essential to building data
>>structures...
There are a couple of uses that I can think of. The most important is
call-by-reference. You want to be able to pass the address of a local
or global variable for modification, or pass a pointer to large object
to avoid copying.
In languages like Pascal, this doesn't look like a pointer (which can
really only point to the heap), but in C it's a pointer just like a
heap pointer.
In Java this is necessarily a heap pointer - you can't call by
reference and you can't point to a non-object.
Another use, as was pointed out, is statically constructed linked
structures.
--
mac the naïf
.
Re: thread specific information ... Some of these bugs are directly related to the aforementioned "programming techniques", so such things should always be viewed with caution. ...Heap is at best "casually" thread-specific. ... If it keeps that pointer to itself there's no reason for another thread to access it, ... Again, this effectively allocates GLOBALLY visible memory to which only one thread is granted a pointer; but there's nothing to prevent that thread from making a pointer visible to other threads, or to keep other threads from accidentally "scribbling" over the data via a random uninitialized pointer. ... (comp.programming.threads)
Re: Garbage collectable pinned arrays! ... Pinning is an explicit... I've already given two examples of APIs in widespread use which require a buffer to stay in one position after the initial function call which accepts the pointer.... That means a one time cost to pin a buffer that lives until the end of the process, if you do this early in the process you won't suffer from fragmentation of the gen0 heap as this object will end on the gen2 heap anyway. ... If this doesn't suits your needs, then you will have to use the Marshal class or GCHandle.Alloc, carefully considering it's costs.... (microsoft.public.dotnet.languages.csharp)
Re: ptrs validity ... I have a pointer that points to an unknown heap memory block,...hardware checked segment for each allocation. ... (comp.lang.c)
Heap corruption error. ... I'm battling a heap corruption error....pBlockHeaderPrev pointer points to the block I just came from. ... The pBlockHeaderNext pointer looks valid in that it's most significant ... reallocated and the write is corrupting the linked list. ... (microsoft.public.vc.mfc)