Server for Information Technologies ������ ��������������
������� �������������� ����������
(095) 932-9212, 932-9213, 939-0783
E-mail: [email protected]
������ �������� ����(!) ������������� ���������� CIT Forum CD-ROM

MALLOC(3X)

��������
malloc, free, realloc, calloc, mallopt, mallinfo - ������� ��������� ����������� ������

���������

	#include <malloc.h>
	
	char *malloc (size)
	unsigned size;
	
	void free (ptr)
	char *ptr;
	
	char *realloc (ptr, size)
	char *ptr;
	unsigned size;
	
	char *calloc (nelem, elsize)
	unsigned nelem, elsize;
	
	int mallopt (cmd, value)
	int cmd, value;
	
	struct mallinfo mallinfo ( )

��������
������� malloc � free ������������� ������� ������������� �������� ��������� � ������������ ������, ���������� ����������� ������� ������ malloc(3C). ����������� ������� ��������� � ���������� malloc � ������������ ��� ������������� ����� -lmalloc ������ cc(1)ld(1).

������� malloc ���������� ��������� �� ���� �������� �� ����� size ����, ������� ����� ������������ � ������������ �����.

���������� ������� free �������� ��������� �� ����, �������������� ���������� � ������� malloc; ����� ���������� free ���� ����� ���� ������� �����, � ���������� � ��� ���������� �������� (��. ������ �������� ������� mallopt, ������� M_KEEP).

� ������ ������ �� ������� �����, ����������� �������� malloc, � ����� ��� ������ ������� free � ����������, �� ���������� ����������� malloc, ������ ����� �������������.

������� realloc �������� ������ �����, �� ������� ��������� ptr, �� ������� size � ���������� ��������� �� �������� ��������� ����. ����� ����������� ����� �� ����������� �� ������ � ������� �������� �� ����������.

������� calloc �������� ������������ ��� ������� �� nelem ���������, ������ �������� elsize ����, � ��������� ������ ������.

� ������� ������� mallopt ����� ��������� ����������� ��������� � ������������ ������. ����������� ��������� �������� ��������� cmd:
M_MXFAST ���������� �������� maxfast ������ ��������� value. �������� ������� ����� ����� ��� ������� ������ ������, ������ ������� �� ����������� maxfast, � ����� �� �������� ����� ������ ������ ��. ��������������� �������� maxfast ����� 24.
M_NLBLKS ���������� �������� numblks ������ ��������� value. ������ �� �������������� "������� �����" �������� numblks ������. ����� ������ ������ ���� ������ 0; ��������������� �������� numblks ����� 100.
M_GRAIN ���������� �������� grain ������ ��������� value. ������� ���� ������, �� ������������� maxfast, ����������� ����� �� ���������� �������� grain. �������� grain ������ ���� ������ 0; ��������������� �������� ������, ����� ���������� ���������� ������������ �� ������� ������ ������ ����. ��� ��������� grain �������� value ����������� ����� �� ���������� �������� �������� �� ���������.
M_KEEP ��������� ������ � ������������� ����� �� ��������� ������� ������� malloc, realloc ��� calloc. ��� ����� ������������� ������ ��� ������������� �� ������ ������� malloc; ������������ �� �� �������������.

��������� �������� ��������� cmd ���������� �� ���������� ����� <malloc.h>.

������� mallopt ����� �������� ��������� ���, �� ������ �� ��������� ������� ���������� �����.

������� mallinfo ������ ���������� �� ������������� ������. ��� ���������� ���������:

struct mallinfo { int arena; /* ����� ������ ����������� ��-�� */ int ordblks; /* ����� ������� ������ */ int smblks; /* ����� ��������� ������ */ int hblks; /* ����� ����������� ������ */ int hblkhd; /* ��-�� � ���������� ������. ������ */ int usmblks; /* ��-�� � ���-��� ��������� ������ */ int fsmblks; /* ��-�� � ����. ��������� ������ */ int uordblks; /* ��-�� � ���-��� ������� ������ */ int fordblks; /* ��-�� � ����. ������� ������ */ int keepcost; /* ����� �� ���-�� ����� ���������� */ }

��������� ���������� �� ���������� ����� <malloc.h>.

������ �� ������� ��������� ���������� ��������� �� ������� ������, ���������� (����� ���������� �������������� ���� ���������) ��� �������� ������������ ������.

�����

	/usr/lib/libmalloc.a

��. �����
brk(2), malloc(3C).

�����������
������� malloc, realloc � calloc ���������� ������ ��������� NULL, ���� ��� ������������ ���������� ������. ����� realloc ���������� ��������� NULL, �� ����, �� ������� ��������� ptr, �������� ����������. ���� ������� mallopt ���������� ����� ��������� ������ ��� �� ��������� cmd ��� value ����� ������������ ��������, �� ������������ �� ����. � ��������� ������ ��������� ����� ����.

���������������
�� ��������� � ������� malloc(3C) ��������� ������� ��������� ������ ����� ��������.

������ ��������� ����� ����������� ������, ��� ��� ������������� malloc(3C).

� ������� �� malloc(3C) ��������� ������� �� ������������ ���������� ���������� � ������������� ������ (���� ������ �� �������������� ����� M_KEEP ������� mallopt).

������������������� ����������� malloc(3C) �� ��������������.
Comments: [email protected]
Designed by Andrey Novikov
Copyright © CIT