Example #1
0
globle void* ix_alloc(env_ref env, size_t size)
{
    struct memory_pool_t *memPtr;

    if( size < sizeof(char *))
    {
        size = sizeof(char *);
    }

    if( size >= MEM_TABLE_SIZE )
    {
        return(ix_malloc(env, (unsigned)size));
    }

    memPtr = (struct memory_pool_t *)get_mem_data(env)->mem_table[size];

    if( memPtr == NULL )
    {
        return(ix_malloc(env, (unsigned)size));
    }

    get_mem_data(env)->mem_table[size] = memPtr->next;

    return((void *)memPtr);
}
Example #2
0
globle int ix_free(env_ref env, void* waste, size_t size)
{
    free(waste);

    get_mem_data(env)->amount -= (long)size;
    get_mem_data(env)->calls--;

    return(0);
}
Example #3
0
globle void* ix_malloc(env_ref env, size_t size)
{
    char *memPtr = (char*) malloc(size);

    assert( memPtr == NULL );

    get_mem_data(env)->amount += (long)size;
    get_mem_data(env)->calls++;

    return((void *)memPtr);
}
Example #4
0
globle int ix_release(env_ref env, void *str, size_t size)
{
    struct memory_pool_t *memPtr;

    assert(size == 0);

    if(size < sizeof(char *)) size = sizeof(char *);
    if(size >= MEM_TABLE_SIZE) return(ix_free(env, (void *)str, (unsigned)size));

    memPtr = (struct memory_pool_t *)str;
    memPtr->next = get_mem_data(env)->mem_table[size];
    get_mem_data(env)->mem_table[size] = memPtr;
    return(1);
}
Example #5
0
globle void kernel_mem_init(env_ref env)
{
    int i;

    env_alloc(env, MEMORY_DATA_INDEX, sizeof(struct memory_data_t));

    // TODO: out of mem function

    get_mem_data(env)->mem_table = (struct memory_pool_t **) malloc((size_t)(sizeof(struct memory_pool_t *) *MEM_TABLE_SIZE));

    assert(get_mem_data(env)->mem_table == NULL);

    for(i = 0; i < MEM_TABLE_SIZE; i++) get_mem_data(env)->mem_table[i] = NULL;
}
Example #6
0
globle void *ix_alloc_init(env_ref env, size_t size)
{
    struct memory_pool_t *memPtr;
    char *tmpPtr;
    size_t i;

    if( size < (long)sizeof(char*))
    {
        size = sizeof(char*);
    }

    if( size >= MEM_TABLE_SIZE )
    {
        tmpPtr = (char*) ix_malloc(env, (unsigned)size);

        for( i = 0 ; i < size ; i++ )
        {
            tmpPtr[i] = '\0';
        }

        return((void *)tmpPtr);
    }

    memPtr = (struct memory_pool_t *)get_mem_data(env)->mem_table[size];

    if( memPtr == NULL )
    {
        tmpPtr = (char *)ix_malloc(env, (unsigned)size);

        for( i = 0 ; i < size ; i++ )
        {
            tmpPtr[i] = '\0';
        }

        return((void *)tmpPtr);
    }

    get_mem_data(env)->mem_table[size] = memPtr->next;

    tmpPtr = (char *)memPtr;

    for( i = 0 ; i < size ; i++ )
    {
        tmpPtr[i] = '\0';
    }

    return((void *)tmpPtr);
}
/** Close a memory stream.
 *
 * @param io mem stream
 * @return 0
 */
static int mem_close(IOStream *io){
    MemData *data = get_mem_data(io);
    if(!data->err){
        data->err = ENOTCONN;
    }
    return 0;
}
/** Read bytes from a memory stream into a buffer.
 *
 * @param io mem stream
 * @param buf buffer
 * @param n maximum number of bytes to read
 * @return number of bytes read on success, negative error code otherwise
 */
static int mem_read(IOStream *io, void *buf, size_t n){
    int k;
    MemData *data = get_mem_data(io);
    if(data->err) return -data->err;
    k = mem_len(data);
    if(n > k){
        n = k;
    }
    mem_get(data, buf, n);
    data->lo += n;
    return n;
}
/** Write bytes from a buffer into a memory stream.
 * The internal buffer is expanded as needed to hold the data,
 * up to the stream maximum (if specified). If the buffer cannot
 * be expanded -ENOMEM is returned.
 *
 * @param io mem stream
 * @param buf buffer
 * @param n number of bytes to write
 * @return number of bytes written on success, negative error code otherwise
 */
static int mem_write(IOStream *io, const void *msg, size_t n){
    int room;
    MemData *data = get_mem_data(io);
    if(data->err) return -data->err;
    room = mem_room(data);
    if(n > room){
        int err = mem_expand(data, n - room);
        if(err) return err;
    }
    mem_put(data, msg, n);
    data->hi += n;
    return n;
}
Example #10
0
guint8* retro_core_get_memory (RetroCore* self, RetroMemoryType id, int* length) {
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (length != NULL, NULL);

	retro_core_push_cb_data (self);

	RetroModule* module = self->module;

	RetroGetMemoryData get_mem_data = retro_module_get_get_memory_data (module);
	RetroGetMemorySize get_mem_size = retro_module_get_get_memory_size (module);

	guint8* data = get_mem_data (id);
	gsize size = get_mem_size (id);

	retro_core_pop_cb_data ();

	data = g_memdup (data, size);
	*length = (gint) (data ? size : 0);

	return data;
}
Example #11
0
globle long int ix_mem_used_update(env_ref env, long int value)
{
    get_mem_data(env)->amount += value;
    return(get_mem_data(env)->amount);
}
/** Get the number of bytes available to read.
 *
 * @param io memory stream
 * @return number of bytes
 */
int mem_stream_avail(IOStream *io){
    MemData *data = get_mem_data(io);
    return (data->err ? -data->err : mem_len(data));
}
Example #13
0
globle long int ix_mem_used(env_ref env)
{
    return(get_mem_data(env)->amount);
}
/** Test if a memory stream has an error.
 *
 * @param io mem stream
 * @return 0 if ok, error code otherwise
 */
static int mem_error(IOStream *io){
    MemData *data = get_mem_data(io);
    return data->err;
}
/** Free a memory stream.
 *
 * @param io mem stream
 */
static void mem_free(IOStream *io){
    MemData *data = get_mem_data(io);
    deallocate(data->buf);
    memzero(data, sizeof(*data));
    deallocate(data);
}
Example #16
0
globle long int ix_mem_reqs(env_ref env)
{
    return(get_mem_data(env)->calls);
}
Example #17
0
globle long int ix_mem_reqs_update(env_ref env, long int value)
{
    get_mem_data(env)->calls += value;
    return(get_mem_data(env)->calls);
}