Solved

What's the limit?

Posted on 2004-08-30
8
185 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Intraweb download file link ? 1 134
How to debug For loops? 3 49
Find and Replace Stream with 0s 8 63
Delphi: barcode reading on android platform 1 30
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…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

803 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