eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'ExternalAddress':

Home

everywhere
www.exept.de
for:
[back]

Class: ExternalAddress


Inheritance:

   Object
   |
   +--ExternalAddress
      |
      +--OSHandle

Package:
stx:libbasic
Category:
System-Support
Version:
rev: 1.25 date: 2010/04/08 11:57:19
user: cg
file: ExternalAddress.st directory: libbasic
module: stx stc-classLibrary: libbasic
Author:
Claus Gittinger

Description:


Instances of this class represent external (non-Smalltalk) addresses.
They are only useful to represent handles as returned by C functions
as smalltalk objects. 
For example, Window- or WidgetIDs (which are actually 32 bit pointers) could be represented this way
(better create a handle-subclass for it, to care for proper finalization).
(you should not use SmallIntegers for this, since they can only represent 31
 bits; LargeIntegers could be used in theory, but it is not a very good style
 to do so, since it makes things a bit cryptic - having ExternalAddresses
 around makes things pretty clear in inspectors etc.).

There is not much you can do with ExternalAddresses on the smalltalk level;
creation/use should be done in primitive C-code via 
   __MKEXTERNALADDRESS(voidPtr) and __ExternalAddressVal(obj).

ExternallAddresses are much like ExternalBytes - however, the latter
allow you to access bytes via indexed at:/at:put: messages.
ExternalAddresses do not allow such accesses (they are meant to remain anonymous, opaque handles).
Also, memory blocks which are freeable should be represented as ExternalBytes.


Related information:

    ByteArray
    ExternalBytes
    ExternalFunction
    [how to write primitive code]

Class protocol:

instance creation
o  newAddress: addr

queries
o  isBuiltInClass
return true if this class is known by the run-time-system.
Here, true is returned.

o  pointerSize
answer the size in bytes of a pointer


Instance protocol:

Compatibility-Squeak
o  beNull

accessing
o  address
return the start address as an integer

o  instVarAt: index
redefined to suppress direct access to my address, which is a non-object

o  instVarAt: index put: newAddress
redefined to suppress direct access to my address, which is a non-object

comparing
o  = anExternalAddress
return true, if two externalAddress instance represent the same
C pointer

o  hash
return a number useful for hashing

converting
o  asExternalAddress
convert to an ExternalAddress.
Useful to convert subclasses

o  asExternalBytes
return an ExternalBytes object pointing to where the receiver points to.
Use of this is not recommended; primitives which return externalAddresses
dont think that access to the memory is required/useful, while primitives
which do think so should return an externalBytes instance right away.

o  copyCStringFromHeap

printing & storing
o  printOn: aStream
return a printed representation of the receiver

private-accessing
o  setAddress: anInteger
set the address

o  setAddressFromBytes: aByteArray
set the address from a pointer to which we have a pointer to


Examples:


To pass some C-pointer from primitive code to smalltalk: ... RETURN (__MKEXTERNALADDRESS(foo)); pass it back to C and use it there: ... if (__isExternalAddress(anExternalAddress)) { ptr = __externalAddressVal(anExternalAddress)); } ... concrete example: test1 %{ static char foo[] = {'h', 'e' ,'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '\n'}; RETURN (__MKEXTERNALADDRESS(foo)); %} test2:anExternalAddress %{ if (__isExternalAddress(anExternalAddress)) { printf(__externalAddressVal(anExternalAddress)); RETURN (self); } %}

ST/X 6.1.1; WebServer 1.620 at exept:8081; Wed, 23 May 2012 09:03:10 GMT