19982009 Ericsson AB. All Rights Reserved. The contents of this file are subject to the Erlang Public License, Version 1.1, (the "License"); you may not use this file except in compliance with the License. You should have received a copy of the Erlang Public License along with this software. If not, it can be retrieved online at http://www.erlang.org/. Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. erl_set_memory_block Patrik Nyblom 98-08-05 A erl_set_memory_block.xml
erl_set_memory_block Custom memory allocation for Erlang on VxWorks®

This documentation is specific to VxWorks.

The function/command initiates custom memory allocation for the Erlang emulator. It has to be called before the Erlang emulator is started and makes Erlang use one single large memory block for all memory allocation.

The memory within the block can be utilized by other tasks than Erlang. This is accomplished by calling the functions , and instead of , and respectively.

The purpose of this is to avoid problems inherent in the VxWorks systems library. The memory allocation within the large memory block avoids fragmentation by using an "address order first fit" algorithm. Another advantage of using a separate memory block is that resource reclamation can be made more easily when Erlang is stopped.

The function is callable from any C program as an ordinary 10 argument function as well as from the commandline.

interl_set_memory_block(size_t size, void *ptr, int warn_mixed_malloc, int realloc_always_moves, int use_reclaim, ...) Specify parameters for Erlang internal memory allocation.

The function is called before Erlang is started to specify a large memory block where Erlang can maintain memory internally.

Parameters:

size_t size The size in bytes of Erlang's internal memory block. Has to be specified. Note that the VxWorks system uses dynamic memory allocation heavily, so leave some memory to the system. void *ptr

A pointer to the actual memory block of size . If this is specified as 0 (NULL), Erlang will allocate the memory when starting and will reclaim the memory block (as a whole) when stopped.

If a memory block is allocated and provided here, the etc routines can still be used after the Erlang emulator is stopped. The Erlang emulator can also be restarted while other tasks using the memory block are running without destroying the memory. If Erlang is to be restarted, also set the flag.

If 0 is specified here, the Erlang system should not be stopped while some other task uses the memory block (has called ).

int warn_mixed_malloc

If this flag is set to true (anything else than 0), the system will write a warning message on the console if a program is mixing normal with or .

int realloc_always_moves

If this flag is set to true (anything else than 0), all calls to result in a moved memory block. This can in certain conditions give less fragmentation. This flag may be removed in future releases.

int use_reclaim

If this flag is set to true (anything else than 0), all memory allocated with is automatically reclaimed as soon as a task exits. This is very useful to make writing port programs (and other programs as well) easier. Combine this with using the routines etc. specified in the reclaim.h file delivered in the Erlang distribution.

Return Value:

Returns 0 (OK) on success, otherwise a value <> 0.

interl_memory_show(...) A utility similar to VxWorks , but for the Erlang memory area.

Return Value:

Returns 0 (OK) on success, otherwise a value <> 0.

interl_mem_info_get(MEM_PART_STATS *stats) A utility similar to VxWorks , but for the Erlang memory area.

Parameter:

MEM_PART_STATS *stats A pointer to a MEM_PART_STATS structure as defined in ]]>. A successful call will fill in all fields of the structure, on error all fields are left untouched.

Return Value:

Returns 0 (OK) on success, otherwise a value <> 0

NOTES

The memory block used by Erlang actually does not need to be inside the area known to ordinary . It is possible to set the preprocessor symbol when compiling the wind kernel and then use user reserved memory for Erlang. Erlang can therefor utilize memory above the 32 Mb limit of VxWorks on the PowerPC architecture.

Example:

In config.h for the wind kernel:

In the start-up script/code for the VxWorks node:

Setting the flag decreases performance of the system, but makes programming much easier. Other similar facilities are present in the Erlang system even without using a separate memory block. The routines called , and provide the same facilities by using VxWorks own . Similar routines exist for files, see the file in the distribution.