User's Guide
Reference Manual
Release Notes
PDF
Top

Erlang Run-Time System Application (ERTS)
Reference Manual
Version 5.7.4

Expand All
Contract All

Table of Contents

- erl_prim_loader
  - Top of manual page
  - start/3
  - get_file/1
  - get_path/0
  - list_dir/1
  - read_file_info/1
  - set_path/1
- erlang
  - Top of manual page
  - abs/1
  - adler32/1
  - adler32/2
  - adler32_combine/3
  - erlang:append_element/2
  - apply/2
  - apply/3
  - atom_to_binary/2
  - atom_to_list/1
  - binary_to_atom/2
  - binary_to_existing_atom/2
  - binary_to_list/1
  - binary_to_list/3
  - bitstring_to_list/1
  - binary_to_term/1
  - bit_size/1
  - erlang:bump_reductions/1
  - byte_size/1
  - erlang:cancel_timer/1
  - check_process_code/2
  - concat_binary/1
  - crc32/1
  - crc32/2
  - crc32_combine/3
  - date/0
  - decode_packet/3
  - delete_module/1
  - erlang:demonitor/1
  - erlang:demonitor/2
  - disconnect_node/1
  - erlang:display/1
  - element/2
  - erase/0
  - erase/1
  - erlang:error/1
  - erlang:error/2
  - exit/1
  - exit/2
  - float/1
  - float_to_list/1
  - erlang:fun_info/1
  - erlang:fun_info/2
  - erlang:fun_to_list/1
  - erlang:function_exported/3
  - garbage_collect/0
  - garbage_collect/1
  - get/0
  - get/1
  - erlang:get_cookie/0
  - get_keys/1
  - erlang:get_stacktrace/0
  - group_leader/0
  - group_leader/2
  - halt/0
  - halt/1
  - erlang:hash/2
  - hd/1
  - erlang:hibernate/3
  - integer_to_list/1
  - erlang:integer_to_list/2
  - iolist_to_binary/1
  - iolist_size/1
  - is_alive/0
  - is_atom/1
  - is_binary/1
  - is_bitstring/1
  - is_boolean/1
  - erlang:is_builtin/3
  - is_float/1
  - is_function/1
  - is_function/2
  - is_integer/1
  - is_list/1
  - is_number/1
  - is_pid/1
  - is_port/1
  - is_process_alive/1
  - is_record/2
  - is_record/3
  - is_reference/1
  - is_tuple/1
  - length/1
  - link/1
  - list_to_atom/1
  - list_to_binary/1
  - list_to_bitstring/1
  - list_to_existing_atom/1
  - list_to_float/1
  - list_to_integer/1
  - erlang:list_to_integer/2
  - list_to_pid/1
  - list_to_tuple/1
  - load_module/2
  - erlang:load_nif/2
  - erlang:loaded/0
  - erlang:localtime/0
  - erlang:localtime_to_universaltime/2
  - erlang:localtime_to_universaltime/3
  - make_ref/0
  - erlang:make_tuple/2
  - erlang:make_tuple/3
  - erlang:max/2
  - erlang:md5/1
  - erlang:md5_final/1
  - erlang:md5_init/0
  - erlang:md5_update/2
  - erlang:memory/0
  - erlang:memory/1
  - erlang:min/2
  - module_loaded/1
  - erlang:monitor/2
  - monitor_node/2
  - erlang:monitor_node/3
  - node/0
  - node/1
  - nodes/0
  - nodes/1
  - now/0
  - open_port/2
  - erlang:phash/2
  - erlang:phash2/2
  - pid_to_list/1
  - port_close/1
  - port_command/2
  - erlang:port_command/3
  - port_connect/2
  - port_control/3
  - erlang:port_call/3
  - erlang:port_info/1
  - erlang:port_info/2
  - erlang:port_to_list/1
  - erlang:ports/0
  - pre_loaded/0
  - erlang:process_display/2
  - process_flag/2
  - process_flag/3
  - process_info/1
  - process_info/2
  - processes/0
  - purge_module/1
  - put/2
  - erlang:raise/3
  - erlang:read_timer/1
  - erlang:ref_to_list/1
  - register/2
  - registered/0
  - erlang:resume_process/1
  - round/1
  - self/0
  - erlang:send/2
  - erlang:send/3
  - erlang:send_after/3
  - erlang:send_nosuspend/2
  - erlang:send_nosuspend/3
  - erlang:set_cookie/2
  - setelement/3
  - size/1
  - spawn/1
  - spawn/2
  - spawn/3
  - spawn/4
  - spawn_link/1
  - spawn_link/2
  - spawn_link/3
  - spawn_link/4
  - spawn_monitor/1
  - spawn_monitor/3
  - spawn_opt/2
  - spawn_opt/3
  - spawn_opt/4
  - spawn_opt/5
  - split_binary/2
  - erlang:start_timer/3
  - statistics/1
  - erlang:suspend_process/2
  - erlang:suspend_process/1
  - erlang:system_flag/2
  - erlang:system_info/1
  - erlang:system_monitor/0
  - erlang:system_monitor/2
  - erlang:system_monitor/2
  - erlang:system_profile/0
  - erlang:system_profile/2
  - term_to_binary/1
  - term_to_binary/2
  - throw/1
  - time/0
  - tl/1
  - erlang:trace/3
  - erlang:trace_delivered/1
  - erlang:trace_info/2
  - erlang:trace_pattern/2
  - erlang:trace_pattern/3
  - trunc/1
  - tuple_size/1
  - tuple_to_list/1
  - erlang:universaltime/0
  - erlang:universaltime_to_localtime/2
  - unlink/1
  - unregister/1
  - whereis/1
  - erlang:yield/0
- init
  - Top of manual page
  - boot/1
  - get_args/0
  - get_argument/1
  - get_arguments/0
  - get_plain_arguments/0
  - get_status/0
  - reboot/0
  - restart/0
  - script_id/0
  - stop/0
  - stop/1
- zlib
  - Top of manual page
  - open/0
  - close/1
  - deflateInit/1
  - deflateInit/2
  - deflateInit/6
  - deflate/2
  - deflate/3
  - deflateSetDictionary/2
  - deflateReset/1
  - deflateParams/3
  - deflateEnd/1
  - inflateInit/1
  - inflateInit/2
  - inflate/2
  - inflateSetDictionary/2
  - inflateReset/1
  - inflateEnd/1
  - setBufSize/2
  - getBufSize/1
  - crc32/1
  - crc32/2
  - crc32/3
  - crc32_combine/4
  - adler32/2
  - adler32/3
  - adler32_combine/4
  - compress/1
  - uncompress/1
  - zip/1
  - unzip/1
  - gzip/1
  - gunzip/1
- epmd
- erl
- erlc
- werl
- escript
- erlsrv
- start_erl
- erl_set_memory_block
  - Top of manual page
  - erl_set_memory_block()
  - erl_memory_show()
  - erl_mem_info_get()
- run_erl
- start
- erl_driver
  - Top of manual page
  - driver_system_info()
  - driver_output()
  - driver_output2()
  - driver_output_binary()
  - driver_outputv()
  - driver_vec_to_buf()
  - driver_set_timer()
  - driver_cancel_timer()
  - driver_read_timer()
  - driver_get_now()
  - driver_select()
  - driver_alloc()
  - driver_realloc()
  - driver_free()
  - driver_alloc_binary()
  - driver_realloc_binary()
  - driver_free_binary()
  - driver_binary_get_refc()
  - driver_binary_inc_refc()
  - driver_binary_dec_refc()
  - driver_enq()
  - driver_pushq()
  - driver_deq()
  - driver_sizeq()
  - driver_enq_bin()
  - driver_pushq_bin()
  - driver_peekq()
  - driver_enqv()
  - driver_pushqv()
  - driver_pdl_create()
  - driver_pdl_lock()
  - driver_pdl_unlock()
  - driver_pdl_get_refc()
  - driver_pdl_inc_refc()
  - driver_pdl_dec_refc()
  - driver_monitor_process()
  - driver_demonitor_process()
  - driver_get_monitored_process()
  - driver_compare_monitors()
  - add_driver_entry()
  - remove_driver_entry()
  - erl_errno_id()
  - set_busy_port()
  - set_port_control_flags()
  - driver_failure_eof()
  - driver_failure_atom()
  - driver_failure_posix()
  - driver_failure()
  - driver_connected()
  - driver_caller()
  - driver_output_term()
  - driver_mk_atom()
  - driver_mk_port()
  - driver_send_term()
  - driver_async ()
  - driver_async_cancel()
  - driver_lock_driver()
  - driver_create_port()
  - erl_drv_thread_create()
  - erl_drv_thread_opts_create()
  - erl_drv_thread_opts_destroy()
  - erl_drv_thread_exit()
  - erl_drv_thread_join()
  - erl_drv_thread_self()
  - erl_drv_equal_tids()
  - erl_drv_mutex_create()
  - erl_drv_mutex_destroy()
  - erl_drv_mutex_lock()
  - erl_drv_mutex_trylock()
  - erl_drv_mutex_unlock()
  - erl_drv_cond_create()
  - erl_drv_cond_destroy()
  - erl_drv_cond_signal()
  - erl_drv_cond_broadcast()
  - erl_drv_cond_wait()
  - erl_drv_rwlock_create()
  - erl_drv_rwlock_destroy()
  - erl_drv_rwlock_rlock()
  - erl_drv_rwlock_tryrlock()
  - erl_drv_rwlock_runlock()
  - erl_drv_rwlock_rwlock()
  - erl_drv_rwlock_tryrwlock()
  - erl_drv_rwlock_rwunlock()
  - erl_drv_tsd_key_create()
  - erl_drv_tsd_key_destroy()
  - erl_drv_tsd_set()
  - erl_drv_tsd_get()
  - erl_drv_putenv()
  - erl_drv_getenv()
- driver_entry
- erts_alloc
- erl_nif
  - Top of manual page
  - enif_get_data()
  - enif_alloc()
  - enif_free()
  - enif_is_binary()
  - enif_inspect_binary()
  - enif_alloc_binary()
  - enif_release_binary()
  - enif_get_int()
  - enif_get_ulong()
  - enif_get_list_cell()
  - enif_make_binary()
  - enif_make_badarg()
  - enif_make_int()
  - enif_make_ulong()
  - enif_make_atom()
  - enif_make_tuple()
  - enif_make_list()
  - enif_make_list_cell()
  - enif_make_string()

# erl_set_memory_block

### C LIBRARY

erl_set_memory_block

### LIBRARY SUMMARY

Custom memory allocation for Erlang on VxWorks®

### DESCRIPTION

This documentation is specific to VxWorks.

The erl_set_memory_block 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 sys_alloc, sys_realloc and sys_free instead of malloc, realloc and free respectively.

The purpose of this is to avoid problems inherent in the VxWorks systems malloc 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 erl_set_memory_block function is callable from any C program as an ordinary 10 argument function as well as from the commandline.

### EXPORTS

int erl_set_memory_block(size_t size, void *ptr, int warn_mixed_malloc, int realloc_always_moves, int use_reclaim, ...)

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 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 sys_alloc 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 use_reclaim flag.

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

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 malloc with sys_realloc or sys_free.

int realloc_always_moves

  If this flag is set to true (anything else than 0), all calls to sys_realloc 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 sys_alloc 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 save_open etc. specified in the reclaim.h file delivered in the Erlang distribution.

Return Value:

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

int erl_memory_show(...)

Return Value:

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

int erl_mem_info_get(MEM_PART_STATS *stats)

Parameter:

MEM_PART_STATS *stats
  A pointer to a MEM_PART_STATS structure as defined in <memLib.h>. 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 malloc. It is possible to set the USER_RESERVED_MEM 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:

          #undef LOCAL_MEM_AUTOSIZE
          #undef LOCAL_MEM_SIZE
          #undef USER_RESERVED_MEM

          #define LOCAL_MEM_SIZE        0x05000000
          #define USER_RESERVED_MEM     0x03000000

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

    erl_set_memory_block(sysPhysMemTop()-sysMemTop(),sysMemTop(),0,0,1);

Setting the use_reclaim 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 save_malloc, save_realloc and save_free provide the same facilities by using VxWorks own malloc. Similar routines exist for files, see the file reclaim.h in the distribution.