Solved

What's the limit?

Posted on 2004-08-30
8
183 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

760 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

19 Experts available now in Live!

Get 1:1 Help Now