free a based based variable

This is a discussion on free a based based variable within the pl1 forums in Programming Languages category; How do we test whether a based variable is freed or not after the free statement. Actually I have written a program where I am freeing the nodes of a linked list in a loop. But after freeing those when I am trying to display the values again it is showing the previous values except the first noe. If anybody have any material relating to this please share with me....

Go Back   Application Development Forum > Programming Languages > pl1

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 01-26-2008, 12:29 PM
Papu
Guest
 
Default free a based based variable

How do we test whether a based variable is freed or not after the free
statement. Actually I have written a program where I am freeing the
nodes of a linked list in a loop. But after freeing those when I am
trying to display the values again it is showing the previous values
except the first noe.

If anybody have any material relating to this please share with me.
Reply With Quote
  #2  
Old 01-26-2008, 06:11 PM
John W. Kennedy
Guest
 
Default Re: free a based based variable

Papu wrote:
> How do we test whether a based variable is freed or not after the free
> statement.


You can't. The closest you can come is to set any appropriate pointer
variables to NULL. Then, later, if the pointer is NULL, you'll know the
resource was freed.

> Actually I have written a program where I am freeing the
> nodes of a linked list in a loop. But after freeing those when I am
> trying to display the values again it is showing the previous values
> except the first noe.


Freeing them doesn't erase them, or make them inaccessible. They /may/
be erased, or otherwise overwritten, or made inaccessible, after being
freed, but it is not guaranteed whether or when any of these things may
happen. If you want them to be erased, erase them yourself before freeing.

In general, this is true of all languages. Free means free -- you're
giving the memory back to the system; what the system does with it
afterwards is none of your business.

--
John W. Kennedy
"The grand art mastered the thudding hammer of Thor
And the heart of our lord Taliessin determined the war."
-- Charles Williams. "Mount Badon"
Reply With Quote
  #3  
Old 01-26-2008, 07:56 PM
Peter Flass
Guest
 
Default Re: free a based based variable

Papu wrote:
> How do we test whether a based variable is freed or not after the free
> statement. Actually I have written a program where I am freeing the
> nodes of a linked list in a loop. But after freeing those when I am
> trying to display the values again it is showing the previous values
> except the first noe.
>
> If anybody have any material relating to this please share with me.


If I understand you, you're saying you can still access the BASED
variables after FREE? FREE doesn't make the memory inaccessible, it
just allows it to be reused later if necessary, therefore most likely
the data will still be there, even after it's freed.

Reply With Quote
  #4  
Old 01-26-2008, 08:03 PM
glen herrmannsfeldt
Guest
 
Default Re: free a based based variable

Peter Flass wrote:

(snip)

> If I understand you, you're saying you can still access the BASED
> variables after FREE? FREE doesn't make the memory inaccessible, it
> just allows it to be reused later if necessary, therefore most likely
> the data will still be there, even after it's freed.


I had a program some years ago (many years ago) that used CONTROLLED
variables. It was accidentally freeing them and reallocating them in
exactly the same place such that I didn't notice the bug for a long
time. Then something changed...

-- glen

Reply With Quote
  #5  
Old 01-27-2008, 06:26 PM
robin
Guest
 
Default Re: free a based based variable

"Papu" <srbehera@gmail.com> wrote in message
news:d6283c63-5ca1-4fb3-8a27-dcd842418cf1@k39g2000hsf.googlegroups.com...
> How do we test whether a based variable is freed or not after the free
> statement. Actually I have written a program where I am freeing the
> nodes of a linked list in a loop. But after freeing those when I am
> trying to display the values again it is showing the previous values
> except the first noe.


You aren't able to display the values of nodes
after they have been freed. Once freed, the nodes
don't exist. (Their values remain in storage until
overwritten, however. But they are inaccessible.)

> If anybody have any material relating to this please share with me.


Any PL/I book dealing with linked lists should be of help.


Reply With Quote
  #6  
Old 01-28-2008, 09:03 PM
James J. Weinkam
Guest
 
Default Re: free a based based variable

robin wrote:
> "Papu" <srbehera@gmail.com> wrote in message
> news:d6283c63-5ca1-4fb3-8a27-dcd842418cf1@k39g2000hsf.googlegroups.com...
>> How do we test whether a based variable is freed or not after the free
>> statement. Actually I have written a program where I am freeing the
>> nodes of a linked list in a loop. But after freeing those when I am
>> trying to display the values again it is showing the previous values
>> except the first noe.

>
> You aren't able to display the values of nodes
> after they have been freed. Once freed, the nodes
> don't exist. (Their values remain in storage until
> overwritten, however. But they are inaccessible.)


That depends on the implementation. In some implementations, unless the
storage has been reallocated and values have been assigned to the new
allocation, if you keep a pointer to freed based storage it can
generally still be referred to and most of the value will still be
there. Some of the value may have been overlaid by control information
used by the storage allocator.

>
>> If anybody have any material relating to this please share with me.

>
> Any PL/I book dealing with linked lists should be of help.
>
>

Reply With Quote
  #7  
Old 01-30-2008, 08:12 AM
robin
Guest
 
Default Re: free a based based variable

"James J. Weinkam" <jjw@cs.sfu.ca> wrote in message news:OPvnj.44006$fj2.3065@edtnps82...
> robin wrote:
> > "Papu" <srbehera@gmail.com> wrote in message
> > news:d6283c63-5ca1-4fb3-8a27-dcd842418cf1@k39g2000hsf.googlegroups.com...
> >> How do we test whether a based variable is freed or not after the free
> >> statement. Actually I have written a program where I am freeing the
> >> nodes of a linked list in a loop. But after freeing those when I am
> >> trying to display the values again it is showing the previous values
> >> except the first noe.

> >
> > You aren't able to display the values of nodes
> > after they have been freed. Once freed, the nodes
> > don't exist. (Their values remain in storage until
> > overwritten, however. But they are inaccessible.)

>
> That depends on the implementation.


Once the object has been freed, consider it gone
forever. It is in error to try to reference the storage
area that it occupied.

> In some implementations, unless the
> storage has been reallocated and values have been assigned to the new
> allocation, if you keep a pointer to freed based storage it can
> generally still be referred to and most of the value will still be
> there. Some of the value may have been overlaid by control information
> used by the storage allocator.


Trying to do what you suggest is a recipe for disaster.


Reply With Quote
  #8  
Old 01-30-2008, 04:32 PM
James J. Weinkam
Guest
 
Default Re: free a based based variable

robin wrote:
> "James J. Weinkam" <jjw@cs.sfu.ca> wrote in message news:OPvnj.44006$fj2.3065@edtnps82...
>> robin wrote:
>>> "Papu" <srbehera@gmail.com> wrote in message
>>> news:d6283c63-5ca1-4fb3-8a27-dcd842418cf1@k39g2000hsf.googlegroups.com...
>>>> How do we test whether a based variable is freed or not after the free
>>>> statement. Actually I have written a program where I am freeing the
>>>> nodes of a linked list in a loop. But after freeing those when I am
>>>> trying to display the values again it is showing the previous values
>>>> except the first noe.
>>> You aren't able to display the values of nodes
>>> after they have been freed. Once freed, the nodes
>>> don't exist. (Their values remain in storage until
>>> overwritten, however. But they are inaccessible.)

>> That depends on the implementation.

>
> Once the object has been freed, consider it gone
> forever. It is in error to try to reference the storage
> area that it occupied.


Of course it's an error; I never said otherwise. But is also a fact
that with some implementations, I suspect most, a pointer to based
storage (or any other storage for that matter) that has been freed can
still address the memory and unless that memory has subsequently been
rellocated and had new values assigned it will continue to hold the
previous value. I am certainly not advocating doing this on purpose.
I'm just saying what is likely to happen if you do it inadvertently.
Since there is no reliable protection against it. it behooves
programmers to be careful.
>
>> In some implementations, unless the
>> storage has been reallocated and values have been assigned to the new
>> allocation, if you keep a pointer to freed based storage it can
>> generally still be referred to and most of the value will still be
>> there. Some of the value may have been overlaid by control information
>> used by the storage allocator.

>
> Trying to do what you suggest is a recipe for disaster.
>
>

You seem unable to distinguish between advocating doing something and
explaining what will happen if it is done unintentionally.

It is also possible that the storage has been reallocated and then
almost anything can happen depending on what has been assigned to the
new variables stored in those locations.

The point is that since most implementations do not ensure that attempts
to reference freed storage are guaranteed to fail, incorrect programs
frequently seem to work for many years then suddenly fail when some
seemingly unrelated circumstance changes.
Reply With Quote
  #9  
Old 02-01-2008, 06:35 AM
robin
Guest
 
Default Re: free a based based variable

"James J. Weinkam" <jjw@cs.sfu.ca> wrote in message news:C16oj.164$C61.92@edtnps89...
> robin wrote:
> > "James J. Weinkam" <jjw@cs.sfu.ca> wrote in message news:OPvnj.44006$fj2.3065@edtnps82...
> >> robin wrote:
> >>> "Papu" <srbehera@gmail.com> wrote in message
> >>> news:d6283c63-5ca1-4fb3-8a27-dcd842418cf1@k39g2000hsf.googlegroups.com...
> >>>> How do we test whether a based variable is freed or not after the free
> >>>> statement. Actually I have written a program where I am freeing the
> >>>> nodes of a linked list in a loop. But after freeing those when I am
> >>>> trying to display the values again it is showing the previous values
> >>>> except the first noe.
> >>> You aren't able to display the values of nodes
> >>> after they have been freed. Once freed, the nodes
> >>> don't exist. (Their values remain in storage until
> >>> overwritten, however. But they are inaccessible.)
> >> That depends on the implementation.

> >
> > Once the object has been freed, consider it gone
> > forever. It is in error to try to reference the storage
> > area that it occupied.

>
> Of course it's an error; I never said otherwise.


On the contrary, you implied that such objects could be
accessed as if it was normal.

> But is also a fact
> that with some implementations, I suspect most, a pointer to based
> storage (or any other storage for that matter) that has been freed can
> still address the memory and unless that memory has subsequently been
> rellocated and had new values assigned it will continue to hold the
> previous value. I am certainly not advocating doing this on purpose.
> I'm just saying what is likely to happen if you do it inadvertently.
> Since there is no reliable protection against it. it behooves
> programmers to be careful.
> >
> >> In some implementations, unless the
> >> storage has been reallocated and values have been assigned to the new
> >> allocation, if you keep a pointer to freed based storage it can
> >> generally still be referred to and most of the value will still be
> >> there. Some of the value may have been overlaid by control information
> >> used by the storage allocator.

> >
> > Trying to do what you suggest is a recipe for disaster.


> You seem unable to distinguish between advocating doing something and
> explaining what will happen if it is done unintentionally.


Your post made no such qualification, and as such
was bound to be interpreted by the OP as a feature
that could be utilised in programs, as that was the way
it worked.


Reply With Quote
  #10  
Old 02-18-2008, 01:14 PM
Papu
Guest
 
Default Re: free a based based variable

Thanks a lot guys for your valuable answers to my query. Nice to know
something useful
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 05:04 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.