Solved

What's the limit?

Posted on 2004-08-30
8
184 Views
Last Modified: 2010-04-05
Anyone know what the limit is on the Live Pointers used by a program and what a "normal" amount is?

Any insight or information would be appreciated too.
0
Comment
Question by:foxjax
  • 3
  • 3
  • 2
8 Comments
 
LVL 14

Accepted Solution

by:
Pierre Cornelius earned 250 total points
ID: 11929423
To my knowledge, this is limited only by available memory. A pointer is merely a reference to an address and takes up 4 bytes.

As to what is "normal", I don't think there is such a thing. The amount of pointers used will depend entirely on your requirements.
0
 
LVL 17

Assisted Solution

by:Wim ten Brink
Wim ten Brink earned 250 total points
ID: 11929600
The normal amount of Live Pointers would be 0... Live Pointers are memory leaks and you don't want any. But nothing is perfect and leaks just happen. Try to keep the amount of memory lost due to leakage as small as possible if your application is supposed to run for long times. If your application intends to start and stop within a few minutes in general then don't worry too much about memory leakage since once the process is stopped, all memory (including the leaked memory) will be released again by the OS. It's not permanently lost.
But say, if your application is supposed to run 24/7 then a memory loss of 1 MB per hour would be very catastrofic. It would eat 24 MB each day, 168 MB per week and soon you'd have to restart the application because all memory is gone. You can't prevent memory loss, but in these cases you should try to reduce it even more.
Then again, if you write a text editor that leaks 10 MB per hour and in general it only runs for 30 minutes then why bother? Sloppy programming, true. But unless someone keeps it running all day, it wouldn't bother people that much.

The amount of maximum Live Pointers basically depends on the memory size of the objects that those pointers are pointing at...
0
 

Author Comment

by:foxjax
ID: 11929650
Thanks Workshop_Alex

I assume the "normal amount of Live Pointers would be 0" is when you exit the program and not when it is running.  

It is when a program is running i was trying to find information on - luckily my program exits with zero live pointers left open :)  (i checked it with Memproof)
0
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 11929761
Your assumption is correct. :-)
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:foxjax
ID: 11929781
Thanks to both PierreC and Workshop_Alex

I now have a much better understanding of Live Pointers....Just one more item i can mark as done on my "Learning Delphi" list.

i am raising the points so i can split them among both of you - 250 points and a grade A each.

Thanks again.
0
 
LVL 14

Expert Comment

by:Pierre Cornelius
ID: 11929799
I wrote the following but before posting it, all uncertainties were answered. I'm posting it anyway just for further reference...

Thanks Fox. Glad to help.



Alex

Why do you say "Live pointers are memory leaks" ? If all live pointers are memory leaks, then where does memory usage fit in? Perhaps my understanding of live pointer is incorrect? My understanding is that a pointer is live until such time as the memory it references is freed. Therefore, I am faced with a bit of a contradiction:

I.e. I want to use some memory but don't want memory leaks. At the same time, I can't have a pointer referencing some memory used without it being a leak?

All pointers used in programs have to be allocated memory for i.e. 4 bytes per pointer.
The allocation and de-allocation of memory pointed to is another matter. The question on whether or not it is live is answered simply by whether or not the memory referenced by the pointer has been allocated and/or deallocated.
You don't HAVE TO allocate the memory that is pointed to to make some use of it (the pointer) as this may have been done by some other part of the program. e.g.

procedure temp;
var SomeList: TList;
    i: integer;
    Fruit : Array [0..4] of string;
    MyFavourite: pointer;
begin
  Fruit[0]:='Apple';
  Fruit[1]:='Pear';
  Fruit[2]:='Banana';
  Fruit[3]:='Peach';
  Fruit[4]:='StrawBerry';

  SomeList:= TList.Create;
  for i:= low(Fruit) to High(Fruit) do
  begin
    SomeList.Add(pointer(Fruit[i]));
    if Fruit[i] = 'Peach'
      then MyFavourite:= SomeList.Items[i];
  end;
  SomeList.Free; //but don't free related memory, this
                 //will happen when it becomes out of
                 //scope i.e. when the procedure completes
                 //and local variables are freed;

  ShowMessage(pAnsiChar(MyFavourite));
end;
...

MyFavourite would be a live pointer until such time as the memory used for Fruit[3] is deallocated. (e.g. if used as a local variable, until such time as the function/procedure completed).

Is this question relating to memory leaks at all or are we misinterpreting what is asked? Maybe Foxjax can elaborate on what he means.


Regards
Pierre
0
 

Author Comment

by:foxjax
ID: 11930349
No, the question was not regarding Memory Leaks - more a question of what are Live Pointers and how many is too many in a program.
0
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 11934530
Pierre, live pointers are pointers that are pointing to allocated memory. To be exact, they are pointing to memory areas that haven't been freed. They are, therefore, live. And as long as you need them, no problem. The example you provided is actually the opposite, an invalid pointer.

A good article can be found at http://bdn.borland.com/article/0,1410,28344,00.html but it's more about preventing memory leaks.

Some code like this will create a "Live pointer" error:

procedure Bug1;
var Ptr: Pointer;
begin
  Ptr := GetMem(1024);
end;

As you see, a pointer is pointing to a block of memory but the memory is never freed. It won't ever be freed either. In some languages, these live pointers are collected by the garbage collector and will be freed once the system has some idle time available. But with Delphi it would never be freed. Basically, it just means the developer has forgotten to free some pointer. The pointer that's forgotten is the live pointer. The allocated memory is the leak. With garbage collection, live pointers are listed though and freed by the collector.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now