How are Smalltalk objects represented in memory?

VA Smalltalk is a "100% VisualAge compatible" IDE that includes the original VisualAge technology and the popular VA Assist and WidgetKit add-ons.

Moderators: Eric Clayberg, wembley, tc, Diane Engles, solveig

How are Smalltalk objects represented in memory?

Postby DEBRO » Wed Jul 15, 2009 6:43 am

Hi there,

I've always wondered how Smalltalk objects are represented in memory but never asked. I assume when objects are created that memory space is reserved for the instance variables and the Smalltalk objects actually point to these memory spaces. I also assume that the methods are stored in memory for the first instance of the object and each instance points to these methods.

For instance, if I have an object Person defined as

Code: Select all
Object subclass: #Person
    instanceVariableNames: 'firstName lastName'
    classVariableNames: ''
    poolDictionaries: ''

firstName

   ^firstName

firstName: aString

   firstName := aString

lastName

   ^lastName

lastName: aString

   lastName := aString

printName

   ^'%1 %2' bindWith: self firstName with: self lastName


I assume the Smalltalk representation of this has pointers to the memory spaces held by firstName and lastName. I also assume the Smalltalk representation has pointers to the method #printName and uses the pointers to firstName and lastName for the actual values.

Does anyone know how the objects are represented in memory when they are created? Or can anyone point me to a document or book that explains how memory is allocated for Smalltalk objects? Again, I've been curious about this for years but have not found anything on the subject.
Take care,
Dennis
DEBRO
 
Posts: 21
Joined: Thu Aug 28, 2008 9:07 am

Re: How are Smalltalk objects represented in memory?

Postby rjs » Thu Jul 16, 2009 1:03 pm

DEBRO wrote:I also assume that the methods are stored in memory for the first instance of the object and each instance points to these methods.

No. No one instance is special compared to any other. In fact, the key point you have missed is that EVERYTHING is an object. Even the class itself. This means that an instance has some kind of linkage to its class, which can most easily be imagined as just another object reference. The class object itself has a variety of instance variables to hold the collection of methods defined by it. It also has a linkage to its class, a metaclass object which defines the class-side behaviour. And of course, both the class and metaclass know their super class, etc. It is a very complex, but strangely elegant, design that I have never really felt I understood in an absolute sense.

DEBRO wrote:I assume the Smalltalk representation of this has pointers to the memory spaces held by firstName and lastName. I also assume the Smalltalk representation has pointers to the method #printName and uses the pointers to firstName and lastName for the actual values.

Again, keep thinking object references for pointers and objects for memory spaces. For example, your firstName instance may be no where near the object that references it terms of memory layout. Perhaps you could regard each object as a single memory space populated with pointers to other objects. Furthermore, the so-called pointer may be a direct memory address of the object's memory space, or it could be an index through an address mapping table.

DEBRO wrote:Does anyone know how the objects are represented in memory when they are created?

That depends on the particular implementation. It is not specified by the ANSI Standard.

DEBRO wrote:Or can anyone point me to a document or book that explains how memory is allocated for Smalltalk objects? Again, I've been curious about this for years but have not found anything on the subject.

Adele Goldberg's Smalltalk: The Language and its Implementation is considered the bible for that. It is a very readable explanation, and if you succeed in finding the "blue" book as opposed to the "purple" edition, it will include a specification of how to write the virtual machine in Smalltalk itself. Also, squeak.org almost certainly will have some documentation on their implementation (Squeak).
rjs
 
Posts: 39
Joined: Thu Mar 27, 2008 11:07 am
Location: Port Perry, Ontario, Canada

Re: How are Smalltalk objects represented in memory?

Postby DEBRO » Fri Jul 31, 2009 8:10 am

Hi there,

Thank you so much for the information. I will be trying to hunt down this book.

I've always wondered how objects where represented in memory. Knowing this helps me support some arguments I've had about some object designs I've seen.
Take care,
Dennis
DEBRO
 
Posts: 21
Joined: Thu Aug 28, 2008 9:07 am

Re: How are Smalltalk objects represented in memory?

Postby wembley » Fri Jul 31, 2009 10:15 am

You can find "Smalltalk-80: The Language and Its Implementation" (as well as many other very useful Smalltalk books) on Stephane Ducasse's Free Online Smalltalk Books page: http://stephane.ducasse.free.fr/FreeBooks.html
John O'Keefe [|], Principal Smalltalk Architect, Instantiations Inc.
wembley
Moderator
 
Posts: 405
Joined: Mon Oct 16, 2006 3:01 am
Location: Durham, NC


Return to VA Smalltalk 7.0, 7.5 & 8.0

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest