MEM
***
This module offers you basic memory management

This module should be always included as one of first modules.

proc mem.init
=============
desc:	Initializes module
args:	none
ret:	CF = 1 on error
uses:	nothing
note:	- choose lower values for exit codes, some system limit them to lesser
	values than dword

proc mem.uninit
===============
desc:	Uninitalizes module
args:	none
ret:	CF = 1 on error
uses:	nothing
note:


proc mem.alloc size
===================
desc:	Allocates block of memory
args:	size	- size of block to allocate in bytes
ret:	CF = 1 on error, otherwise
	EAX = pointer to first byte of block
uses:	nothing
note:	returned pointer is always >= 10000h
	contents of allocated memory are unknown (TODO - use alloc0)

proc mem.free blockptr
======================
desc:	Frees block of memory allocated using mem.alloc
args:	blockptr	- pointer into allocated block
ret:	CF = 1 on error
uses:	nothing
note:	after error, consider block as freed, don't use it anymore

proc mem.realloc blockptr, newsize
==================================
desc:	Reallocates block of memory (eg. changes it's size)
args:	blockptr	- pointer into allocated block
	size		- new size of block
ret:	CF = 1 on error, otherwise
	EAX = pointer to first byte of new block
uses:	nothing
note:	- returned pointer is always >= 10000h
	- data in block are not modified (only data at the end of block are
	deleted if newsize < previous size)
	- if block is enlarging, then contents of added memory are unknown 
	(TODO - use realloc0)
	- block can move to other place in memory, so previous pointers into
	block become invalid (so rather use indexes in block than pointers)

proc mem.size blockptr
======================
desc:	Returns size of allocated block
args:	blockptr	- pointer into allocated block
ret:	CF = 1 on error, otherwise
	EAX = size of block in bytes
uses:	nothing
note:

proc mem.fill dest, size, value
===============================
desc:	Fills block of memory with constant dword value
args:	dest	- pointer to beginning of memory block to where to copy
	size	- number of bytes to copy
	value	- dword filler value
ret: 	CF = 1 on error, otherwise
	eax = dest (for use with nested libcalls)
note:	- module doesn't have to be initalized for this to work
	- use dword operator to push string as filler value, like:
	  libcall mem.fill, [buf], [size], dword "abcd"

proc mem.copy dest, src, size
=============================
desc:	Copies block of memory
args:	dest	- pointer to beginning of memory block to where to copy
	src	- pointer to beginning of memory block from where to copy
	size	- number of bytes to copy
ret:	CF = 1 on error, otherwise
	eax = dest (for use with nested libcalls)
note:	- module doesn't have to be initalized for this to work

proc mem.cmp dest, src, size
============================
desc:	Compares blocks of memory
args:	dest	- pointer to beginning of first memory block
	src	- pointer to beginning of second memory block
	size	- number of bytes to compare
ret:	CF = 1 on error, otherwise
	ZF = 1 if blocks are equal, otherwise
	eax = offset (not pointer) where blocks differ
note:	- module doesn't have to be initalized for this to work



Example of usage:
=================

include 'fasmlib/mem.inc'
	;initialize module
	libcall mem.init
	jc error

	;allocate 4096 bytes
	libcall mem.alloc, 4096
	jc error
	mov ebx,eax

	;fill it with spaces
	libcall mem.fill, ebx, 4096, dword "    "

	;reallocate it to 8192 bytes
	libcall mem.realloc, ebx, 8192
	jc error
	mov ebx,eax

	;get new size
	libcall mem.size, ebx
	jc error	

	;check #1 - has block right size?
	cmp eax, 8192
	jne error

	;check #2 - did the block remain unchaged?
	mov al, ' '
	mov ecx, 4096
	mov edi, ebx
	cld			; ? TODO
	repe scasb
	jne error

	;all OK, free block
	libcall mem.free, ebx
	jc error

	;and stop working with mem module
	libcall mem.uninit
	jc error
	...
error:
	libcall mem.uninit
	...
