--- a/ExternalStructure.st Mon Jan 28 14:43:30 2013 +0100
+++ b/ExternalStructure.st Mon Jan 28 19:01:20 2013 +0100
@@ -9,7 +9,6 @@
other person. No title to or ownership of the software is
hereby transferred.
"
-
"{ Package: 'stx:libbasic' }"
ExternalBytes subclass:#ExternalStructure
@@ -65,12 +64,56 @@
fromExternalAddress:anExternalAddress
^ self new fromExternalAddress:anExternalAddress
+!
+
+new
+ "allocate some memory usable for data;
+ the memory is not controlled by the garbage collector.
+ Return a corresponding ExternalBytes object or raise MallocFailure (if malloc fails).
+
+ Use this, if you have to pass a block of bytes to some
+ external destination (such as a C function) which does not copy the
+ data, but instead keeps a reference to it. For example, many functions
+ which expect strings simply keep a ref to the passed string - for those,
+ an ST/X string-pointer is not the right thing to pass, since ST/X objects
+ may change their address.
+
+ DANGER ALERT: the memory is NOT automatically freed until it is either
+ MANUALLY freed (see #free) or the returned externalBytes object
+ is unprotected or the classes releaseAllMemory method is called."
+
+ ^ super new:(self sizeof)
+
+ "Modified: / 20-12-2010 / 16:22:51 / cg"
+!
+
+unprotectedNew
+ "allocate some memory usable for data;
+ the memory is under the control of the garbage collector.
+ Return a corresponding ExternalBytes object or raise MallocFailure (if malloc fails).
+
+ DANGER ALERT: the memory block as allocated will be automatically freed
+ as soon as the reference to the returned externalBytes object
+ is gone (by the next garbage collect).
+ If the memory has been passed to a C-function which
+ remembers this pointer, bad things may happen ...."
+
+ ^ super unprotectedNew:(self sizeof)
! !
!ExternalStructure class methodsFor:'queries'!
cType
^ cType
+!
+
+sizeof
+ "the sizeof my instances in bytes"
+
+ cType notNil ifTrue:[
+ ^ cType sizeof
+ ].
+ self subclassResponsibility
! !
!ExternalStructure methodsFor:'private'!
@@ -82,5 +125,6 @@
!ExternalStructure class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic/ExternalStructure.st,v 1.3 2006-06-20 15:27:17 ca Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic/ExternalStructure.st,v 1.4 2013-01-28 18:01:20 cg Exp $'
! !
+