Zen API
 All Classes Files Functions Variables Typedefs Macros Groups Pages
kMemory Class Reference

Description

Represents an in-memory stream.

+ Inheritance diagram for kMemory:

Public Member Functions

kStatus kMemory_Allocate (kMemory memory, kSize initialCapacity)
 Allocates an auto-sizing, internally-managed buffer for the memory stream. More...
 
void * kMemory_At (kMemory memory, kSize offset)
 Returns a pointer to the memory buffer at the specified position. More...
 
kStatus kMemory_Attach (kMemory memory, void *buffer, kSize position, kSize length, kSize capacity)
 Attaches the memory stream to an external, fixed-capacity buffer. More...
 
kSize kMemory_Capacity (kMemory memory)
 Returns the current capacity of the memory buffer. More...
 
kStatus kMemory_Construct (kMemory *memory, kAlloc allocator)
 Constructs a kMemory object. More...
 
k64u kMemory_Length (kMemory memory)
 Returns the current length of the memory buffer. More...
 
k64u kMemory_Position (kMemory memory)
 Returns the current position of the read/write pointer, relative to the beginning of the buffer. More...
 
kStatus kMemory_SetLength (kMemory memory, kSize length)
 Sets the reported length of the memory buffer. More...
 
kAlloc kObject_Alloc (kObject object)
 Gets the memory allocator associated with this object. More...
 
kStatus kObject_Clone (kObject *object, kObject source, kAlloc allocator)
 Constructs a new object by copying an existing object, including any aggregated child elements. More...
 
kStatus kObject_Destroy (kObject object)
 Destroys the object. More...
 
kStatus kObject_Dispose (kObject object)
 Destroys the object and any aggregated child elements. More...
 
kBool kObject_Equals (kObject object, kObject other)
 Determines whether the object is equal to another object. More...
 
kSize kObject_HashCode (kObject object)
 Gets a hash code representing the state of this object. More...
 
kBool kObject_Is (kObject object, kType type)
 Determines whether this object is an instance of the specified type. More...
 
kBool kObject_IsShared (kObject object)
 Reports whether the object is currently shared (reference count greater than one). More...
 
kStatus kObject_SetPool (kObject object, kObjectPool pool)
 Sets the object pool associated with this object. More...
 
kStatus kObject_Share (kObject object)
 Increments the reference count associated with this object. More...
 
kSize kObject_Size (kObject object)
 Estimates the memory consumed by this object, including any aggregated child elements. More...
 
kType kObject_Type (kObject object)
 Returns the type of the object. More...
 
k64u kStream_BytesRead (kStream stream)
 Reports the number of bytes read from this stream. More...
 
k64u kStream_BytesWritten (kStream stream)
 Reports the number of bytes written to this stream. More...
 
kStatus kStream_ClearStats (kStream stream)
 Clears stream statistics (e.g. More...
 
kStatus kStream_Copy (kStream stream, kStream source, kSize size)
 Copies the specified number of bytes from one stream to another. More...
 
kStatus kStream_CopyEx (kStream stream, kStream source, kSize size, kCallbackFx progress, kPointer context)
 Copies the specified number of bytes from one stream to another, with progress feedback. More...
 
kStatus kStream_Flush (kStream stream)
 Flushes buffered writes to the underlying medium. More...
 
kStatus kStream_Read (kStream stream, void *buffer, kSize size)
 Reads the specified number of bytes from the stream. More...
 
kStatus kStream_ReadSome (kStream stream, void *buffer, kSize minCount, kSize maxCount, kSize *bytesRead)
 Reads up to the specified number of bytes from the stream. More...
 
kStatus kStream_Seek (kStream stream, k64s offset, kSeekOrigin origin)
 Moves the read/write pointer to the specified location. More...
 
kStatus kStream_Write (kStream stream, const void *buffer, kSize size)
 Writes the specified number of bytes to the stream. More...
 

Member Function Documentation

kStatus kMemory_Allocate ( kMemory  memory,
kSize  initialCapacity 
)

Allocates an auto-sizing, internally-managed buffer for the memory stream.

Parameters
memorykMemory object.
initialCapacityInitial capacity of the buffer, in bytes.
Returns
Operation status.
void * kMemory_At ( kMemory  memory,
kSize  offset 
)

Returns a pointer to the memory buffer at the specified position.

Parameters
memorykMemory object.
offsetPosition of interest, in bytes.
Returns
Operation status.
kStatus kMemory_Attach ( kMemory  memory,
void *  buffer,
kSize  position,
kSize  length,
kSize  capacity 
)

Attaches the memory stream to an external, fixed-capacity buffer.

Parameters
memorykMemory object.
bufferData buffer.
positionCurrent read/write position, relative to start of buffer.
lengthLength of valid data contained in the buffer, in bytes.
capacityTotal size of the buffer, in bytes.
Returns
Operation status.
kSize kMemory_Capacity ( kMemory  memory)

Returns the current capacity of the memory buffer.

Parameters
memorykMemory object.
Returns
Capacity of the memory buffer.
kStatus kMemory_Construct ( kMemory memory,
kAlloc  allocator 
)

Constructs a kMemory object.

By default, an auto-sizing, internally-managed buffer is used.

Parameters
memoryDestination for the constructed object handle.
allocatorMemory allocator (or kNULL for default).
Returns
Operation status.
k64u kMemory_Length ( kMemory  memory)

Returns the current length of the memory buffer.

Parameters
memorykMemory object.
Returns
Length of the memory buffer.
k64u kMemory_Position ( kMemory  memory)

Returns the current position of the read/write pointer, relative to the beginning of the buffer.

Parameters
memorykMemory object.
Returns
Position of the write/write pointer.
kStatus kMemory_SetLength ( kMemory  memory,
kSize  length 
)

Sets the reported length of the memory buffer.

Parameters
memorykMemory object.
lengthBuffer length
Returns
Operation status.
kAlloc kObject_Alloc ( kObject  object)
inherited

Gets the memory allocator associated with this object.

Most objects are constructed with an allocator, which is used to allocate the memory required by the object. Objects retain a reference to this allocator to enable further allocations and to free memory when the object is destroyed.

Parameters
objectObject.
Returns
Memory allocator.
See also
kAlloc, kObject_Alloc_
kStatus kObject_Clone ( kObject object,
kObject  source,
kAlloc  allocator 
)
inherited

Constructs a new object by copying an existing object, including any aggregated child elements.

If the source object is an object collection (e.g. kArrayList<kString>), any aggregated child objects are also cloned. In this case, the kObject_Dispose method can be used to free the cloned collection and its associated elements.

This method will fail if the source object (or an aggregated child element) does not support cloning.

Parameters
objectReceives the constructed object.
sourceSource object.
allocatorMemory allocator (or kNULL for default).
Returns
Operation status.
See also
kObject_Dispose
kStatus kObject_Destroy ( kObject  object)
inherited

Destroys the object.

The kObject_Destroy method destroys the object itself and any resources that are owned by the object. See Object Destruction for more information.

When an object is destroyed (or disposed), its reference count is decremented. The object is only truly destroyed when the reference count reaches zero. See Reference Counting for more information.

Parameters
objectObject (or kNULL).
Returns
Operation status.
See also
Object Destruction, Reference Counting
kStatus kObject_Dispose ( kObject  object)
inherited

Destroys the object and any aggregated child elements.

The kObject_Dispose method destroys the object itself, any resources that are owned by the object, and if the object represents a collection of objects, any child objects in the collection. See Object Destruction for more information.

When an object is destroyed (or disposed), its reference count is decremented. The object is only truly destroyed when the reference count reaches zero. See Reference Counting for more information.

Parameters
objectObject (or kNULL).
Returns
Operation status.
See also
Object Destruction, Reference Counting
kBool kObject_Equals ( kObject  object,
kObject  other 
)
inherited

Determines whether the object is equal to another object.

By default, objects are compared by reference; objects are considered equal if the given handles refer to the same object instance. However, some classes override the Equals method to provide a more meaningful comparison (e.g. kString).

Parameters
objectObject.
otherObject for comparison.
Returns
kTRUE if the objects are equal.
kSize kObject_HashCode ( kObject  object)
inherited

Gets a hash code representing the state of this object.

By default, objects return a hash code based on the object handle value. However, some classes override the HashCode method to provide a more useful hash (e.g. kString).

Parameters
objectObject.
Returns
Hash code.
kBool kObject_Is ( kObject  object,
kType  type 
)
inherited

Determines whether this object is an instance of the specified type.

This function compares the type of this object with the given type. An object is considered to be an instance of a given type if a) the type represents a class and this object inherits from (or instantiates) that class, or b) the type represents an interface and this object implements the interface.

Parameters
objectObject.
typeType.
Returns
kTRUE if the object is of the specified type; otherwise kFALSE.
See also
kObject_Is_, kType_Is
kBool kObject_IsShared ( kObject  object)
inherited

Reports whether the object is currently shared (reference count greater than one).

Objects are initialized with a reference count of one. The kObject_Share method can be used to increment the reference count. The kObject_Destroy and kObject_Dispose methods decrease the reference count, and when the reference count reaches zero, the object is actually destroyed/disposed.

This method can be used to determine if the reference count of an object is currently greater than one.

This method is thread-safe.

Parameters
objectObject.
Returns
kTRUE if the object is shared; kFALSE otherwise.
See also
Reference Counting, kObject_Share
kStatus kObject_SetPool ( kObject  object,
kObjectPool  pool 
)
inherited

Sets the object pool associated with this object.

Object pools can be used to implement custom lifecycle management. If an object has an assigned pool, then the kObjectPool_Reclaim method will be called just prior to destruction, to provide an opportunity for the object to be reclaimed.

Parameters
objectObject.
poolPool object (or kNULL to clear the pool assignment).
Returns
Operation status.
kStatus kObject_Share ( kObject  object)
inherited

Increments the reference count associated with this object.

This method is thread-safe.

Parameters
objectObject.
Returns
Operation status.
See also
reference-counting
kSize kObject_Size ( kObject  object)
inherited

Estimates the memory consumed by this object, including any aggregated child elements.

This method can be optionally overridden by kObject-derived classes to report the amount of memory consumed by an object. The default implementation reports only the size of the class instance (additional allocations performed by the class are excluded).

Parameters
objectObject.
Returns
Object size, in bytes.
kType kObject_Type ( kObject  object)
inherited

Returns the type of the object.

Each object is an instance of a specific class type. The type handle returned by this function can be used to learn about the class.

Parameters
objectObject.
Returns
Type.
See also
kType, kObject_Type_
k64u kStream_BytesRead ( kStream  stream)
inherited

Reports the number of bytes read from this stream.

Parameters
streamStream object.
Returns
Count of bytes read.
k64u kStream_BytesWritten ( kStream  stream)
inherited

Reports the number of bytes written to this stream.

Parameters
streamStream object.
Returns
Count of bytes written.
kStatus kStream_ClearStats ( kStream  stream)
inherited

Clears stream statistics (e.g.

BytesRead, BytesWritten).

Parameters
streamStream object.
Returns
Operation Status
kStatus kStream_Copy ( kStream  stream,
kStream  source,
kSize  size 
)
inherited

Copies the specified number of bytes from one stream to another.

Parameters
streamDestination stream.
sourceSource stream.
sizeCount of bytes to be copied.
Returns
Operation status.
kStatus kStream_CopyEx ( kStream  stream,
kStream  source,
kSize  size,
kCallbackFx  progress,
kPointer  context 
)
inherited

Copies the specified number of bytes from one stream to another, with progress feedback.

The specified callback will be invoked to provide feedback on the progress of the operation. The callback 'args' parameter will receive a k32u value representing the percentage completed. The callback is guaranteed to be called at least once if the operation is successful, with a progress value of 100%.

Parameters
streamDestination stream.
sourceSource stream.
sizeCount of bytes to be copied.
progressOptional progress callback (can be kNULL).
contextCallback context.
Returns
Operation status.
kStatus kStream_Flush ( kStream  stream)
inherited

Flushes buffered writes to the underlying medium.

Parameters
streamStream object.
Returns
Operation status.
kStatus kStream_Read ( kStream  stream,
void *  buffer,
kSize  size 
)
inherited

Reads the specified number of bytes from the stream.

Parameters
streamStream object.
bufferDestination for bytes that are read.
sizeCount of bytes to read.
Returns
Operation status.
kStatus kStream_ReadSome ( kStream  stream,
void *  buffer,
kSize  minCount,
kSize  maxCount,
kSize bytesRead 
)
inherited

Reads up to the specified number of bytes from the stream.

Parameters
streamStream object.
bufferDestination for bytes that are read.
minCountMinimum count of bytes to read.
maxCountMaximum count of bytes to read.
bytesReadReceives count of bytes read.
Returns
Operation status.
kStatus kStream_Seek ( kStream  stream,
k64s  offset,
kSeekOrigin  origin 
)
inherited

Moves the read/write pointer to the specified location.

Parameters
streamStream object.
offsetOffset by which to adjust the read/write pointer.
originOrigin to which movement is relative (i.e. begin, current, end).
Returns
Operation status.
kStatus kStream_Write ( kStream  stream,
const void *  buffer,
kSize  size 
)
inherited

Writes the specified number of bytes to the stream.

Parameters
streamStream object.
bufferBytes to be written to the stream.
sizeCount of bytes to be written.
Returns
Operation status.

The documentation for this class was generated from the following file: