For Programmers: Free Programming Magazines  


Home > Archive > Cobol > July 2006 > ALLOCATE revisited









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author ALLOCATE revisited
Roger While

2006-07-05, 3:55 am

I am still having problems understanding this.
Consider :
ALLOCATE based-item-in-whatever-storage RETURNING pointer-1.
......
ALLOCATE based-item-in-whatever-storage RETURNING pointer-2.

Are consecutive ALLOCATE's allowed without an intervening FREE ?
When yes, does the ALLOCATE return new storage or the previously
allocated storage ? (ie. In the example above is pointer-1 equal pointer-2?)

Roger


Rick Smith

2006-07-05, 6:55 pm


"Roger While" <simrw@sim-basis.de> wrote in message
news:e8fu8p$re1$00$1@news.t-online.com...
> I am still having problems understanding this.
> Consider :
> ALLOCATE based-item-in-whatever-storage RETURNING pointer-1.
> .....
> ALLOCATE based-item-in-whatever-storage RETURNING pointer-2.
>
> Are consecutive ALLOCATE's allowed without an intervening FREE ?


Yes, even if the same based item is used for each allocation.

> When yes, does the ALLOCATE return new storage or the previously
> allocated storage ?


For this and all similar examples, new storage.

> (ie. In the example above is pointer-1 equal pointer-2?)


No. 'pointer-1' contains the address of the first allocation;
'pointer-2' and the implicit pointer for 'based-item-in-whatever-storage'
contain the address of the second allocation.



William M. Klein

2006-07-08, 6:55 pm

To go a little farther,

If you coded:

ALLOCATE based-item-in-whatever-storage RETURNING pointer-1.
ALLOCATE based-item-in-whatever-storage RETURNING pointer-1.

with no statements in-between, the storage allocated by the first statement
would be (almost) impossible ever to free. You would get a second allocation
and have "lost" the addressability to the first obtained storage.

(Or at least this is how I remember the definition).

--
Bill Klein
wmklein <at> ix.netcom.com
"Rick Smith" <ricksmith@mfi.net> wrote in message
news:12ao3du9agpl2b5@corp.supernews.com...
>
> "Roger While" <simrw@sim-basis.de> wrote in message
> news:e8fu8p$re1$00$1@news.t-online.com...
>
> Yes, even if the same based item is used for each allocation.
>
>
> For this and all similar examples, new storage.
>
>
> No. 'pointer-1' contains the address of the first allocation;
> 'pointer-2' and the implicit pointer for 'based-item-in-whatever-storage'
> contain the address of the second allocation.
>
>
>



Roger While

2006-07-10, 3:55 am

Nice to see you back Bill.
Hope you had a nice time.

OK. Further clarification requested.
(Abbreviated syntax)
WORKING-STORAGE
01 MYFLD PIC X BASED.

ALLOCATE MYFLD INITIALIZED.

How do I FREE this ?
According to standard, I can't do a
FREE MYFLD.

"1) The data item referenced by data-name-1 shall be of category
data-pointer."

Does this mean I have to :
FREE ADDRESS OF MYFLD

?

Roger

"William M. Klein" <wmklein@nospam.netcom.com> schrieb im Newsbeitrag
news:2eVrg.13993$B62.635@fe07.news.easynews.com...
> To go a little farther,
>
> If you coded:
>
> ALLOCATE based-item-in-whatever-storage RETURNING pointer-1.
> ALLOCATE based-item-in-whatever-storage RETURNING pointer-1.
>
> with no statements in-between, the storage allocated by the first
> statement would be (almost) impossible ever to free. You would get a
> second allocation and have "lost" the addressability to the first obtained
> storage.
>
> (Or at least this is how I remember the definition).
>
> --
> Bill Klein
> wmklein <at> ix.netcom.com
> "Rick Smith" <ricksmith@mfi.net> wrote in message
> news:12ao3du9agpl2b5@corp.supernews.com...
>
>



William M. Klein

2006-07-10, 6:55 pm

That certainly looks like a "good way" to FREE it. Otherwise, either use a
RETURNING clause to the ALLOCATE or a Pointer to the BASED item.

--
Bill Klein
wmklein <at> ix.netcom.com
"Roger While" <simrw@sim-basis.de> wrote in message
news:e8t19a$mcp$00$1@news.t-online.com...
> Nice to see you back Bill.
> Hope you had a nice time.
>
> OK. Further clarification requested.
> (Abbreviated syntax)
> WORKING-STORAGE
> 01 MYFLD PIC X BASED.
>
> ALLOCATE MYFLD INITIALIZED.
>
> How do I FREE this ?
> According to standard, I can't do a
> FREE MYFLD.
>
> "1) The data item referenced by data-name-1 shall be of category
> data-pointer."
>
> Does this mean I have to :
> FREE ADDRESS OF MYFLD
>
> ?
>
> Roger
>
> "William M. Klein" <wmklein@nospam.netcom.com> schrieb im Newsbeitrag
> news:2eVrg.13993$B62.635@fe07.news.easynews.com...
>
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com