# OpenEuphoria Manual

## Euphoria v4.1

routine or constant name search

| Up |  |  | TOC | Index
<< 7 Included Tools | < 8.42 Errors and Warnings | Up: 8 API Reference | 8.44 Machine Level Access > | 9 Release Notes >>

## 8.43 Pseudo Memory

One use is to emulate PBR, such as Euphoria's map and stack types.

#### 8.43.0.1 ram_space

    include std/eumem.e
    namespace eumem
    export sequence ram_space

The (pseudo) RAM heap space. Use malloc to gain ownership to a heap location and free to release it back to the system.

#### 8.43.0.2 malloc

    include std/eumem.e
    namespace eumem
    export function malloc(object mem_struct_p = 1, integer cleanup_p = 1)

allocates a block of (pseudo) memory.

##### Parameters:

1. `mem_struct_p` : The initial structure (sequence) to occupy the allocated block. If this is an integer, a sequence of zero this long is used. The default is the number one, meaning that the default initial structure is `{0}`
2. `cleanup_p` : Identifies whether the memory should be released automatically when the reference count for the handle for the allocated block drops to zero, or when passed to `delete`. If zero, then the block must be freed using the free procedure.

##### Returns:

A handle, to the acquired block. Once you acquire the handle you can use it as needed. Note that if `cleanup_p` is one, then the variable holding the handle must be capable of storing an atom (do not use an integer) as a double floating point value.

##### Example 1:

    my_spot = malloc()
     ram_space[my_spot] = my_data

#### 8.43.0.3 free

    include std/eumem.e
    namespace eumem
    export procedure free(atom mem_p)

deallocates a block of (pseudo) memory.

##### Parameters:

1. `mem_p` : The handle to a previously acquired ram_space location.

##### Comments:

This allows the location to be used by other parts of your application. You should no longer access this location again because it could be acquired by some other process in your application. This routine should only be called if you passed zero as `cleanup_p` to malloc.

##### Example 1:

    my_spot = malloc(1,0)
     ram_space[my_spot] = my_data
         -- . . . do some processing  . . .
     free(my_spot)

#### 8.43.0.4 valid

    include std/eumem.e
    namespace eumem
    export function valid(object mem_p, object mem_struct_p = 1)

validates a block of (pseudo) memory.

##### Parameters:

1. `mem_p` : The handle to a previously acquired ram_space location.
2. `mem_struct_p` : If an integer, this is the length of the sequence that should be occupying the `ram_space` location pointed to by `mem_p`.

##### Returns:

An integer,
0 if either the `mem_p` is invalid or if the sequence at that location is the wrong length.
1 if the handle and contents are okay.

##### Comments:

This can only check the length of the contents at the location. Nothing else is checked at that location.

##### Example 1:

    my_spot = malloc()
     ram_space[my_spot] = my_data
     . . . do some processing  . .
     if valid(my_spot, length(my_data)) then
         free(my_spot)
     end if

| Up |  |  | TOC | Index
<< 7 Included Tools | < 8.42 Errors and Warnings | Up: 8 API Reference | 8.44 Machine Level Access > | 9 Release Notes >>