|
|
6.31 CObject
- Defined in namespace Smalltalk
- Category: Language-C interface
- I am not part of the standard Smalltalk kernel class hierarchy.
My instances contain values that are not interpreted by the Smalltalk
system; they frequently hold "pointers" to data outside of the Smalltalk
environment. The C callout mechanism allows my instances to be transformed
into their corresponding C values for use in external routines.
6.31.1 CObject class: conversion
- scalarIndex
- Nothing special in the default case - answer a CType for the receiver
- type
- Nothing special in the default case - answer a CType for the receiver
6.31.2 CObject class: instance creation
- address: anInteger
- Answer a new object pointing to the passed address, anInteger
- alloc: nBytes
- Allocate nBytes bytes and return an instance of the receiver
- alloc: nBytes type: cTypeObject
- Allocate nBytes bytes and return a CObject of the given type
- new: nBytes
- Allocate nBytes bytes and return an instance of the receiver
6.31.3 CObject: accessing
- address
- Answer the address the receiver is pointing to.
- address: anInteger
- Set the receiver to point to the passed address, anInteger
- at: byteOffset
- Answer some data of the receiver's default type, reading byteOffset bytes after the pointer stored in the receiver
- at: byteOffset put: value
- Store some data of the receiver's default type, writing byteOffset bytes after the pointer stored in the receiver
- printOn: aStream
- Print a representation of the receiver
- type: aCType
- Set the receiver's type to aCType.
- value
- What can I return? So fail
- value: anObject
- What can I set? So fail
6.31.4 CObject: C data access
- at: byteOffset put: aValue type: aType
- Store aValue as data of the given type from byteOffset bytes after the pointer stored in the receiver
- at: byteOffset type: aType
- Answer some data of the given type from byteOffset bytes after the pointer stored in the receiver
- free
- Free the receiver's pointer and set it to null. Big trouble hits you if the receiver doesn't point to the base of a malloc-ed area.
6.31.5 CObject: conversion
- castTo: aType
- Answer another CObject, pointing to the same address as the receiver, but belonging to the aType CType.
- scalarIndex
- Nothing special in the default case - answer the receiver's CType
- type
- Answer a CType for the receiver
6.31.6 CObject: finalization
- finalize
- To make the VM call this, use #addToBeFinalized. It frees automatically any memory pointed to by the CObject. It is not automatically enabled because big trouble hits you if you use #free and the receiver doesn't point to the base of a malloc-ed area.
|