Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

What's the limit?

Posted on 2004-08-30
8
Medium Priority
?
189 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 14

Accepted Solution

by:
Pierre Cornelius earned 1000 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 1000 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

722 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