× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



On Thu, 10 Oct 2002, Smith, Nelson wrote:
>
> 1.)  If I allocate 100 bytes to MyBasingPointer and then I do an EVAL
> AnotherBasingPointer  = MyBasingPointer, does AnotherBasingPointer also
> have 100 bytes allocated to it?  If not, does it have any memory allocated
> to it yet?
>

Umm.. sort-of.   A better way to put it would be "they both have the same
100 bytes allocated to them".

But, I'm pretty sure this is legal:

     c                   alloc     100           p_one
     c                   eval      p_two = p_one
     c                   dealloc                 p_two


> 2.) If AnotherBasingPointer is pointing to the same address as
> MyBasingPointer, and I reallocate 1000 bytes to AnotherBasingPointer, have I
> also reallocated the memory assigned to MyBasingPointer?

No.  REALLOC just allocates new storage, copies the data to it,
deallocates the original storage, and changes your result-field to point
to the new storage.

This means that after your REALLOC, MyBasingPointer will be pointing
to storage that has been deallocated, and AnotherBasingPointer will have
been changed to point to new memory.

You could write your own realloc routine with the same behavior by
doing something like this:  (I didnt test this code, it's just to
illustrate my point)

    P realloc         B
    D realloc         PI
    D   pointer                       *
    D   size                        10I 0
    D   oldsize                     10I 0

    D newptr          S               *

     * allocate new memory:
    c                   alloc     size          newptr

     * copy from old location to new location:
    c                   callp     copy_memory(newptr: pointer: oldsize)

     * get rid of old locations
    c                   dealloc                 pointer

     * now use new location
    c                   eval      pointer = newptr

    c                   return
    P                 E


>
> 3.)  If I have a basing pointer defined globally in a module, can I
> reallocate memory to it in a subprocedure?  Will the new amount of memory
> still be there when the subprocedure ends?
>

Yes.  Memory allocated with ALLOC is not local to the subprocedure.
The memory should remain allocated until either you deallocate it, or
until the activation group ends.

One danger you want to be careful to avoid would be allocating memory
to a pointer that's local to a subprocedure, and then forgetting to
deallocate it.   When you do that, the pointer variable is destroyed when
the subprocedure ends, but the memory is still allocated.   This means
that the memory is still locked, but you can't access it.   It's what
they call a "memory leak", because if it's done multiple times, the
memory seems to be slowly disappearing...

Of course, this memory would still be cleaned up when the activation
group is ended.   (This is another reason why I prefer to use *NEW
activation groups... tho I don't know that I want to start that thread
again)

> 4.)  If I define a basing pointer in a subprocedure as static and allocate
> memory to it, can I use it and reallocate memory to it in the main procedure
> or another subprocedure?

You cannot access a pointer declared in a subprocedure outside the
subprocedure, so there'd be no way to do that.

If you somehow could access the static pointer from outside the
subprocedure (like maybe you had a pointer to the static pointer!) then
you COULD do this, but it would make for confusing code.   If your goal
is to have a pointer that can be used globally, make it global!

But... that memory is still intact, so if you found some way to get
your hands on that pointer, you could use it outside the subprocedure.
>
> 5.)  Is there anyway to work with the allocated memory of a basing pointer
> in a given program from a called service program procedure?  Such as
> MyBasingPointer = AddMoreMemory(MyBasingPointer:MemoryToAdd)

That would be the same as the REALLOC procedure that I just described, but
yes you could do that.   I'm not sure what would happen if the service
program were in a different activation group, though... would it be able
to realloc the memory?   I suspect that it would, but that the memory
would be cleaned up when the service program's activation group was ended
instead of the calling program.    Service programs should always be
*CALLER anyway :)

>
> 6.)  Where is the information regarding how much memory has been allocated
> to a pointer stored?  Is there an API to get at it?  Maybe if I knew this, I
> would be able to determine the answers to the other questions above.


Some way to "watch what is happening" when memory is allocated or
deallocated?   I seem to recall seeing a thread about this in the past,
but I don't remember what they decided or even where I saw the thread :)

It was either in this list or on the MI list...  hmmmm...




As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.