tags:

views:

247

answers:

5

I have been looking at system.pas Delphi can call up to 65,000 memory blocks from windows When Delphi makes an object dose it call a memory block for its data And if so does the class some how load a register with a memory address for that memory block and an address for the methods too that is placed in another register. Does any one know anything about this?

J Lex Dean.

A: 

Where does your "65000 memory blocks" statistic comes from?

When a class instance is Created, the following class method is called before executing the Create method of the class (from _ClassCreate global function, which ensures that the instance is created only once, for all Create nested calls):

class function TObject.NewInstance: TObject;

Which calls GetMem to get memory from the heap, and then the following method:

class function TObject.InitInstance(Instance: Pointer): TObject;

This InitInstance method will:

  1. Call FillChar() to put all the previously allocated memory to 0;
  2. Initialize the Interface Table of the object.

The methods (i.e. not the interfaces) are defined in the class type itself, not during class instance creation.

There is no "register" containing what you say.

You have access to the object memory address by its self variable, or by trans-typing its variable to a pointer:

var O: TObject;
begin
  O := TObject.Create;
  writeln('O memory address is ',pointer(O));
  O.Free;
end;

And before Delphi 2010 and its enhanced RTTI, you don't have access to all methods and fields of an object. Only published properties and methods are accessible to your code. But you must use RTTI. See TypInfo.pas unit.

A.Bouchez
+3  A: 

Have a look at this excellent explanation about what's going on when Delphi creates new Class instances: The Rise and Fall of TObject from Hallvard Vassbotn Although the original article appeared in 1998, most of it is still true for newer Delphi versions. Here is the original article from The Delphi Magazine:The Delphi Magazine, July 1998

iamjoosy
A: 

Thanks thanks thanks You guys Its just the answer I'm interested in

Best regards, Lex Dean

lexdean
This is not a discussion board.
quantumSoup
... "but I'm not going to award an answer or any points for good comments. I am posting this as an answer because I don't have enough points to comment (and never will have if I create a new account for every question"
LeonixSolutions
A: 

I'm hear to learn to make use of this learing I have a big subject to grasp for my goal so thanks for the help as finding that is quite a work in its own. I'm not interested in any points ok so do not give me any

Furthering this subject of TObject creation TClass is the first record in an object and TClass of the last descendant of the object is the end of the memory block. So we introduce a (may I say presedo object) to hold declared memory in the abstract object. I hope you understand what I am saying. I'm wondering if any of these things have been looked at by any other people. I see one option is place some procedure in the last create constructor Another option is is to modify ClassCreate to accommodate this in some way. I do not think setting a known extra size for the last component is always safe or a good use of memory. I can see introducing a particular named byte is one alternative if it can be found by ClassCreate(). As ClassCreate is quite a tricky bit of code as it stands anyway.

If no one has considered this area of coding I wish that Delphi considered like we declare memory with a 'F' and a object with a 'T' an abstract object could be with a 'A' but it does simplify object writing. I would like question Hallvard Vassbotn if he has futhered this field privately him self.

Best regards, Lex Dean

lexdean
@lexdean: if you consider it to be to much of an effort to at least flag the best answer as such you may find one day that you are no longer getting any answers. Take 5 minutes to figure out how SO works, it's really not rocket science. Take a look here 'http://stackoverflow.com/faq'
Lieven
A: 

With GetMem you call from windows a memory block that windows allocates up to 65,000 per process inside the 4 gig space. Depending on the fag depends on if the block is moved when resized with the data relocated in the resize or fixed and other issues. Read about Windows or go to windows.pas and search on memory and call on your Delphi help Thier is a lot of funny things with system.pas like1/ _ObjectProcess as if to add confustion to delphi programmers. Why do they not just put code in TObject. 2/ And how does code measure deliration size of an object.

lexdean
Looks like you are a Delphi programmer who doesn't need any more confusion added.
mghie