Solved

What's the limit?

Posted on 2004-08-30
8
186 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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 11929761
Your assumption is correct. :-)
0
 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Virtuailstring tree compare node issue 14 125
Delphi 2 69
tidtcpserver connection lost handle 2 103
Twebbrowser add css to the header 3 29
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

830 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