Samples

Memory allocator and input stream

MascotCapsule V3 interface is defined for the allocator that allocates the memory, and the stream that loads the data; however, their implementations can vary depending on environments.
In this way, it is possible to use the best implementation according to the environment, for loading the data ( file loading, data transfer via network, etc. ) and allocating the memory.

If the project you are working on requires particular implementations, please follow such requirements.
If there aren't any requirements for implementations, it is necessary to prepare the following interface to accommodate each individual environment.
For details, please refer to the portion of sample code downloadable from the following link, or the sample code implemented in each sample.

Table of contents



1. Memory allocator ( IAllocator )

Implement the following three functions for the memory allocator interface:

(1) void* ( *alloc )( IAllocator* This, hi_uint32 size )

Implement this function so that the memory specified by the size argument will be allocated.
As a return value, return the beginning address of the allocated memory.
When the memory could not be allocated, return 0 as a return value.

(2) void* ( *realloc )( IAllocator* This, void* address, hi_uint32 size )

Currently, this function is not used; it is not necessary to implement this function.

(3) void ( *free )( IAllocator* This, void* address )

Implement this function so that the memory space specified by the address argument will be released.
Depending on what you have implemented in (1), perform the appropriate release process.



2. Input stream ( IIstream )

Implement the following six functions for the input stream interface:

(1) hi_sint8 ( *readSint8 )( IIstream* This )

Implement this function so that a signed 8-bit integer value will be read out.
This function should return the signed 8-bit integer value that was read out, as a return value.
The stream pointer should advance by the byte amount of read out.

(2) hi_sint16 ( *readSint16 )( IIstream* This )

Implement this function so that a signed 16-bit integer value will be read out.
This function should return the signed 16-bit integer value that was read out, as a return value.
The stream pointer should advance by the byte amount of read out.
The stream data to be read out must be in little-endian order.

(3) hi_sint32 ( *readSint32 )( IIstream* This )

Implement this function so that a signed 32-bit integer value will be read out.
This function should return the signed 32-bit integer value that was read out, as a return value.
The stream pointer should advance by the byte amount of read out.
The stream data to be read out must be in little-endian order.

(4) void ( *readBytes )( IIstream* This, hi_byte* buffer, hi_uint32 n )

Implement this function so that an n-byte data will be read out, and stored in the buffer.
The stream pointer should advance by the byte amount of read out.

(5) void ( *skipBytes )( IIstream* This, hi_uint32 n )

Implement this function so that an n-byte data will be skipped.
The stream pointer should advance by the byte amount of skipping.

(6) hi_bool ( *fail )( IIstream* This )

This function should return completion/failure of the read out.
If the required data is successfully read out from the input stream, HI_FALSE should be returned; if the reading out is failed, HI_TRUE should be returned.



Page TopBack