ubinos
Classes | Macros | Typedefs | Functions
heap.h File Reference

ubiclib heap API More...

#include <ubinos_config.h>
#include <ubinos/type.h>

Go to the source code of this file.

Classes

struct  __heap_tip_t
 

Macros

#define HEAP_ERR__POLLUTED_TOP   -21
 
#define HEAP_ERR__POLLUTED_BOTTOM   -22
 
#define HEAP_ERR__POLLUTED_HEADER   -23
 
#define HEAP_ERR__UNSUPPORTED   -24
 

Typedefs

typedef struct __heap_tip_t _heap_tip_t
 
typedef _heap_tip_theap_pt
 

Functions

int ubiclib_heap_comp_init (unsigned int addr, unsigned int size)
 
int ubiclib_heap_comp_init_reent (void)
 
int heap_create (heap_pt *heap_p, unsigned int addr, unsigned int size)
 
int heap_create_ext (heap_pt *heap_p, unsigned int addr, unsigned int size, int algorithm0, int locktype0, unsigned int m0, unsigned int fblcount0, int algorithm1, int locktype1, unsigned int m1, unsigned int fblcount1)
 
int heap_delete (heap_pt *heap_p)
 
void * heap_malloc (heap_pt heap, unsigned int size)
 
void * heap_mallocn (heap_pt heap, unsigned int size)
 
void * heap_mallocr (heap_pt heap, unsigned int size)
 
int heap_free (heap_pt heap, void *ptr)
 
int heap_checkblockboundary (heap_pt heap, void *ptr)
 
int heap_checkblockboundaryall (heap_pt heap)
 
int heap_getblocksize (heap_pt heap, void *ptr, unsigned int *size_p)
 
void * mallocn (size_t size)
 
void * mallocr (size_t size)
 
int heap_getsize (heap_pt heap, unsigned int *size_p)
 
int heap_getrequestedsize (heap_pt heap, unsigned int *size_p)
 
int heap_getrequestedsize_ext (heap_pt heap, unsigned int *size_p, unsigned int *nsize_p, unsigned int *rsize_p)
 
int heap_getrequestedsizemax (heap_pt heap, unsigned int *size_p)
 
int heap_getrequestedsizemax_ext (heap_pt heap, unsigned int *size_p, unsigned int *nsize_p, unsigned int *rsize_p)
 
int heap_getallocatedcount (heap_pt heap, unsigned int *count_p)
 
int heap_getallocatedcount_ext (heap_pt heap, unsigned int *count_p, unsigned int *ncount_p, unsigned int *rcount_p)
 
int heap_getallocatedcountmax (heap_pt heap, unsigned int *count_p)
 
int heap_getallocatedcountmax_ext (heap_pt heap, unsigned int *count_p, unsigned int *ncount_p, unsigned int *rcount_p)
 
int heap_getallocatedsize (heap_pt heap, unsigned int *size_p)
 
int heap_getallocatedsize_ext (heap_pt heap, unsigned int *size_p, unsigned int *nsize_p, unsigned int *rsize_p)
 
int heap_getallocatedsizemax (heap_pt heap, unsigned int *size_p)
 
int heap_getallocatedsizemax_ext (heap_pt heap, unsigned int *size_p, unsigned int *nsize_p, unsigned int *rsize_p)
 
int heap_getfreeblockcount (heap_pt heap, unsigned int *count_p)
 
int heap_getfreeblockcount_ext (heap_pt heap, unsigned int *count_p, unsigned int *ncount_p, unsigned int *rcount_p)
 
int heap_getblockoverhead (heap_pt heap, unsigned int *overhead_p)
 
int heap_printheapinfo (heap_pt heap)
 
unsigned int heap_group_calc_fblcount (unsigned int size, unsigned int m)
 
unsigned int heap_wbuddy_calc_fblcount (unsigned int size, unsigned int m)
 
unsigned int heap_pgroup_calc_fblcount (unsigned int size, unsigned int m)
 

Detailed Description

ubiclib heap API

ubiclib 힙 API를 정의합니다.

Macro Definition Documentation

◆ HEAP_ERR__POLLUTED_BOTTOM

#define HEAP_ERR__POLLUTED_BOTTOM   -22

하위 경계 영역이 오염되었음

◆ HEAP_ERR__POLLUTED_HEADER

#define HEAP_ERR__POLLUTED_HEADER   -23

헤더 경계 영역이 오염되었음

◆ HEAP_ERR__POLLUTED_TOP

#define HEAP_ERR__POLLUTED_TOP   -21

상위 경계 영역이 오염되었음

◆ HEAP_ERR__UNSUPPORTED

#define HEAP_ERR__UNSUPPORTED   -24

지원하지 않는 기능임

Typedef Documentation

◆ _heap_tip_t

typedef struct __heap_tip_t _heap_tip_t

API용 힙 구조체 정의

◆ heap_pt

typedef _heap_tip_t* heap_pt

API용 힙 포인터 형 정의

Function Documentation

◆ heap_checkblockboundary()

int heap_checkblockboundary ( heap_pt  heap,
void *  ptr 
)

메모리 블록의 경계 영역이 오염되었는지 여부를 검사하는 함수

Parameters
heap대상 힙
NULL이면 기본 힙
ptr대상 메모리 블록의 주소
Returns
0: 정상

-1: 오류
-n: n-1 번째 매개변수가 잘못되었음
HEAP_ERR__POLLUTED_TOP : top boundary 영역이 오염되었음
HEAP_ERR__POLLUTED_BOTTOM : bottom boundary 영역이 오염되었음
HEAP_ERR__POLLUTED_HEADER : header boundary 영역이 오염되었음

메모리 블럭 구조

#if !(UBINOS__UBICLIB__EXCLUDE_HEAP_BOUNDARY_CHECK == 1)
         -----------------------------------
         | header boundary                 |
         |        --------                 |
         |        tag                      |
         |        --------                 |
         |        ...                      |
         -----------------------------------
         | top boundary                    |
         -----------------------------------  <---- memory address
         | memory                          |
         |                                 |
         |                                 |
         -----------------------------------
         | tag                             |
         -----------------------------------
         | bottom boundary                 |
         -----------------------------------
#else
         -----------------------------------
         | header tag                      |
         |        --------                 |
         |        ...                      |
         -----------------------------------  <---- memory address
         | memory                          |
         |                                 |
         |                                 |
         -----------------------------------
         | tag                             |
         -----------------------------------
#endif

◆ heap_checkblockboundaryall()

int heap_checkblockboundaryall ( heap_pt  heap)

힙의 모든 메모리 블록들의 경계 영역이 오염되었는지 여부를 검사하는 함수

Parameters
heap대상 힙
NULL이면 기본 힙
Returns
0: 정상

-1: 오류
-n: n-1 번째 매개변수가 잘못되었음

◆ heap_create()

int heap_create ( heap_pt heap_p,
unsigned int  addr,
unsigned int  size 
)

힙을 생성하는 함수

Parameters
heap_p생성한 힙의 주소를 저장할 포인터의 주소
addr힙으로 사용할 메모리의 주소
size힙으로 사용할 메모리의 크기
Returns
0: 성공

-1: 오류
-n: n-1 번째 매개변수가 잘못되었음

◆ heap_create_ext()

int heap_create_ext ( heap_pt heap_p,
unsigned int  addr,
unsigned int  size,
int  algorithm0,
int  locktype0,
unsigned int  m0,
unsigned int  fblcount0,
int  algorithm1,
int  locktype1,
unsigned int  m1,
unsigned int  fblcount1 
)

힙을 생성하는 함수의 확장형

Parameters
heap_p생성한 힙의 주소를 저장할 포인터의 주소
addr힙으로 사용할 메모리의 주소
size힙으로 사용할 메모리의 크기
algorithm0정방향 힙의 알고리즘 (UBINOS__UBICLIB__HEAP_ALGORITHM__...)
locktype0정방향 힙의 잠금 방식 (UBINOS__UBICLIB__HEAP_LOCK_TYPE__...)
m0정방향 힙의 그룹 시스템 M 값
fblcount0정방향 힙의 사용가능 블록 리스트의 수
algorithm1역방향 힙의 알고리즘 (UBINOS__UBICLIB__HEAP_ALGORITHM__...)
locktype1역방향 힙의 잠금 방식 (UBINOS__UBICLIB__HEAP_LOCK_TYPE__...)
m1역방향 힙의 그룹 시스템 M 값
fblcount1역방향 힙의 사용가능 블록 리스트의 수
Returns
0: 성공

-1: 오류
-n: n-1 번째 매개변수가 잘못되었음

◆ heap_delete()

int heap_delete ( heap_pt heap_p)

힙을 제거하는 함수

Parameters
heap_p제거할 힙의 주소가 저장된 포인터의 주소
제거에 성공하면 *heap_p는 NULL이 됨
Returns
0: 성공

-1: 오류
-n: n-1 번째 매개변수가 잘못되었음

◆ heap_free()

int heap_free ( heap_pt  heap,
void *  ptr 
)

메모리 블록을 해제하는 함수

Parameters
heap대상 힙
NULL이면 기본 힙
ptr대상 메모리 블록의 주소
Returns
0: 성공

-1: 오류
-n: n-1 번째 매개변수가 잘못되었음

◆ heap_getallocatedcount()

int heap_getallocatedcount ( heap_pt  heap,
unsigned int *  count_p 
)

힙의 할당된 메모리 블록들의 총 수를 돌려주는 함수

Parameters
heap대상 힙
NULL이면 기본 힙
count_p총 수를 저장할 변수의 주소
Returns
0: 성공

-1: 오류
-n: n-1 번째 매개변수가 잘못되었음
Examples
condvtest04.c, msgqtest04.c, mutextest04.c, semtest04.c, signaltest04.c, stimertest03.c, and tasktest06.c.

◆ heap_getallocatedcount_ext()

int heap_getallocatedcount_ext ( heap_pt  heap,
unsigned int *  count_p,
unsigned int *  ncount_p,
unsigned int *  rcount_p 
)

힙의 할당된 메모리 블록들의 총 수를 돌려주는 함수의 확장형

Parameters
heap대상 힙
NULL이면 기본 힙
count_p총 수를 저장할 변수의 주소
NULL이면 무시함
ncount_p정방향으로 할당된 메모리 블록들의 총 수를 저장할 변수의 주소
NULL이면 무시함
rcount_p역방향으로 할당된 메모리 블록들의 총 수를 저장할 변수의 주소
NULL이면 무시함
Returns
0: 성공

-1: 오류
-n: n-1 번째 매개변수가 잘못되었음

◆ heap_getallocatedcountmax()

int heap_getallocatedcountmax ( heap_pt  heap,
unsigned int *  count_p 
)

힙의 할당된 메모리 블록들의 총 수의 최고 기록을 돌려주는 함수

Parameters
heap대상 힙
NULL이면 기본 힙
count_p총 수의 최고 기록을 저장할 변수의 주소
Returns
0: 성공

-1: 오류
-n: n-1 번째 매개변수가 잘못되었음

◆ heap_getallocatedcountmax_ext()

int heap_getallocatedcountmax_ext ( heap_pt  heap,
unsigned int *  count_p,
unsigned int *  ncount_p,
unsigned int *  rcount_p 
)

힙의 할당된 메모리 블록들의 총 수의 최고 기록을 돌려주는 함수의 확장형

Parameters
heap대상 힙
NULL이면 기본 힙
count_p총 수의 최고 기록을 저장할 변수의 주소
NULL이면 무시함
ncount_p정방향으로 할당된 메모리 블록들의 총 수의 최고 기록을 저장할 변수의 주소
NULL이면 무시함
rcount_p역방향으로 할당된 메모리 블록들의 총 수의 최고 기록을 저장할 변수의 주소
NULL이면 무시함
Returns
0: 성공

-1: 오류
-n: n-1 번째 매개변수가 잘못되었음

◆ heap_getallocatedsize()

int heap_getallocatedsize ( heap_pt  heap,
unsigned int *  size_p 
)

힙의 할당된 메모리 블록들의 총 크기를 돌려주는 함수

Parameters
heap대상 힙
NULL이면 기본 힙
size_p힙의 할당된 메모리 블록들의 총 크기를 저장할 변수의 주소
Returns
0: 성공

-1: 오류
-n: n-1 번째 매개변수가 잘못되었음
Examples
condvtest04.c, msgqtest04.c, mutextest04.c, semtest04.c, signaltest04.c, stimertest03.c, and tasktest06.c.

◆ heap_getallocatedsize_ext()

int heap_getallocatedsize_ext ( heap_pt  heap,
unsigned int *  size_p,
unsigned int *  nsize_p,
unsigned int *  rsize_p 
)

힙의 할당된 메모리 블록들의 총 크기를 돌려주는 함수의 확장형

Parameters
heap대상 힙
NULL이면 기본 힙
size_p힙의 할당된 메모리 블록들의 총 크기를 저장할 변수의 주소
NULL이면 무시함
nsize_p정방향으로 할당된 메모리 블록들의 총 크기를 저장할 변수의 주소
NULL이면 무시함
rsize_p역방향으로 할당된 메모리 블록들의 총 크기를 저장할 변수의 주소
NULL이면 무시함
Returns
0: 성공

-1: 오류
-n: n-1 번째 매개변수가 잘못되었음

◆ heap_getallocatedsizemax()

int heap_getallocatedsizemax ( heap_pt  heap,
unsigned int *  size_p 
)

힙의 할당된 메모리 블록들의 총 크기의 최고 기록을 돌려주는 함수

Parameters
heap대상 힙
NULL이면 기본 힙
size_p총 크기의 최고 기록을 저장할 변수의 주소
Returns
0: 성공

-1: 오류
-n: n-1 번째 매개변수가 잘못되었음

◆ heap_getallocatedsizemax_ext()

int heap_getallocatedsizemax_ext ( heap_pt  heap,
unsigned int *  size_p,
unsigned int *  nsize_p,
unsigned int *  rsize_p 
)

힙의 할당된 메모리 블록들의 총 크기의 최고 기록을 돌려주는 함수의 확장형

Parameters
heap대상 힙
NULL이면 기본 힙
size_p총 크기의 최고 기록을 저장할 변수의 주소
NULL이면 무시함
nsize_p정방향으로 할당된 메모리 블록들의 총 크기의 최고 기록을 저장할 변수의 주소
NULL이면 무시함
rsize_p역방향으로 할당된 메모리 블록들의 총 크기의 최고 기록을 저장할 변수의 주소
NULL이면 무시함
Returns
0: 성공

-1: 오류
-n: n-1 번째 매개변수가 잘못되었음

◆ heap_getblockoverhead()

int heap_getblockoverhead ( heap_pt  heap,
unsigned int *  overhead_p 
)

힙의 메모리 블록 당 부담(overhead)를 돌려주는 함수

Parameters
heap대상 힙
NULL이면 기본 힙
overhead_p메모리 블럭 당 부담(overhead)를 저장할 변수의 주소
Returns
0: 성공

-1: 오류
-n: n-1 번째 매개변수가 잘못되었음

◆ heap_getblocksize()

int heap_getblocksize ( heap_pt  heap,
void *  ptr,
unsigned int *  size_p 
)

메모리 블록의 크기를 돌려주는 함수

Parameters
heap대상 힙
NULL이면 기본 힙
ptr대상 메모리 블록의 주소
size_p크기를 저장할 변수의 주소
Returns
0: 성공

-1: 오류
-n: n-1 번째 매개변수가 잘못되었음

◆ heap_getfreeblockcount()

int heap_getfreeblockcount ( heap_pt  heap,
unsigned int *  count_p 
)

힙의 사용가능 블록의 수를 돌려주는 함수

Parameters
heap대상 힙
NULL이면 기본 힙
count_p총 사용가능 블록의 수를 저장할 변수의 주소
Returns
0: 성공

-1: 오류
-n: n-1 번째 매개변수가 잘못되었음

◆ heap_getfreeblockcount_ext()

int heap_getfreeblockcount_ext ( heap_pt  heap,
unsigned int *  count_p,
unsigned int *  ncount_p,
unsigned int *  rcount_p 
)

힙의 사용가능 블록의 수를 돌려주는 확장형

Parameters
heap대상 힙
NULL이면 기본 힙
count_p총 사용가능 블록의 수를 저장할 변수의 주소
NULL이면 무시함
ncount_p정방향 영역의 사용가능 블록의 수를 저장할 변수의 주소
NULL이면 무시함
rcount_p역방향 영역의 사용가능 블록의 수를 저장할 변수의 주소
NULL이면 무시함
Returns
0: 성공

-1: 오류
-n: n-1 번째 매개변수가 잘못되었음

◆ heap_getrequestedsize()

int heap_getrequestedsize ( heap_pt  heap,
unsigned int *  size_p 
)

힙의 메모리 블록들의 요청 크기의 총 합을 돌려주는 함수

Parameters
heap대상 힙
NULL이면 기본 힙
size_p요청 크기의 총 합을 저장할 변수의 주소
Returns
0: 성공

-1: 오류
-n: n-1 번째 매개변수가 잘못되었음

◆ heap_getrequestedsize_ext()

int heap_getrequestedsize_ext ( heap_pt  heap,
unsigned int *  size_p,
unsigned int *  nsize_p,
unsigned int *  rsize_p 
)

힙의 메모리 블록들의 요청 크기 총 합을 돌려주는 함수의 확장형

Parameters
heap대상 힙
NULL이면 기본 힙
size_p요청 크기의 총 합을 저장할 변수의 주소
NULL이면 무시함
nsize_p정방향으로 할당된 메모리 블록들의 요청 크기의 총 합을 저장할 변수의 주소
NULL이면 무시함
rsize_p역방향으로 할당된 메모리 블록들의 요청 크기의 총 합을 저장할 변수의 주소
NULL이면 무시함
Returns
0: 성공

-1: 오류
-n: n-1 번째 매개변수가 잘못되었음

◆ heap_getrequestedsizemax()

int heap_getrequestedsizemax ( heap_pt  heap,
unsigned int *  size_p 
)

힙의 메모리 블록들의 요청 크기의 총 합의 최고 기록을 돌려주는 함수

Parameters
heap대상 힙
NULL이면 기본 힙
size_p요청 크기의 총 합의 최고 기록을 저장할 변수의 주소
Returns
0: 성공

-1: 오류
-n: n-1 번째 매개변수가 잘못되었음

◆ heap_getrequestedsizemax_ext()

int heap_getrequestedsizemax_ext ( heap_pt  heap,
unsigned int *  size_p,
unsigned int *  nsize_p,
unsigned int *  rsize_p 
)

힙의 메모리 블록들의 요청 크기의 총 합의 최고 기록을 돌려주는 함수의 확장형

Parameters
heap대상 힙
NULL이면 기본 힙
size_p요청 크기의 총 합의 최고 기록을 저장할 변수의 주소
NULL이면 무시함
nsize_p정방향으로 할당된 메모리 블록들의 요청 크기의 총 합의 최고 기록을 저장할 변수의 주소
NULL이면 무시함
rsize_p역방향으로 할당된 메모리 블록들의 요청 크기의 총 합의 최고 기록을 저장할 변수의 주소
NULL이면 무시함
Returns
0: 성공

-1: 오류
-n: n-1 번째 매개변수가 잘못되었음

◆ heap_getsize()

int heap_getsize ( heap_pt  heap,
unsigned int *  size_p 
)

힙의 크기를 돌려주는 함수

Parameters
heap대상 힙
NULL이면 기본 힙
size_p크기를 저장할 변수의 주소
Returns
0: 성공

-1: 오류
-n: n-1 번째 매개변수가 잘못되었음

◆ heap_group_calc_fblcount()

unsigned int heap_group_calc_fblcount ( unsigned int  size,
unsigned int  m 
)

테일드 블록 그룹 시스템의 사용 가능 블록 리스트 수를 개산하는 함수

Parameters
size최대 멤버 수
m최대 멤버 수
Returns
사용 가능 블록 리스트 수

0: 오류

◆ heap_malloc()

void* heap_malloc ( heap_pt  heap,
unsigned int  size 
)

메모리 블록을 할당하는 함수

Parameters
heap대상 힙
NULL이면 기본 힙
size요청 크기
Returns
할당된 메모리 블록의 주소

NULL: 오류

◆ heap_mallocn()

void* heap_mallocn ( heap_pt  heap,
unsigned int  size 
)

정방향으로 메모리 블록을 할당하는 함수

Parameters
heap대상 힙
NULL이면 기본 힙
size요청 크기
Returns
할당된 메모리 블록의 주소

NULL: 오류

◆ heap_mallocr()

void* heap_mallocr ( heap_pt  heap,
unsigned int  size 
)

역방향으로 메모리 블록을 할당하는 함수

Parameters
heap대상 힙
NULL이면 기본 힙
size요청 크기
Returns
할당된 메모리 블록의 주소

NULL: 오류

◆ heap_pgroup_calc_fblcount()

unsigned int heap_pgroup_calc_fblcount ( unsigned int  size,
unsigned int  m 
)

그룹 시스템의 사용 가능 블록 리스트 수를 개산하는 함수

Parameters
size최대 멤버 수
m최대 멤버 수
Returns
사용 가능 블록 리스트 수

0: 오류

◆ heap_printheapinfo()

int heap_printheapinfo ( heap_pt  heap)

힙의 정보를 출력하는 함수

Parameters
heap대상 힙
NULL이면 기본 힙
Returns
0: 성공

-1: 오류
-n: n-1 번째 매개변수가 잘못되었음
Examples
misctest01.c.

◆ heap_wbuddy_calc_fblcount()

unsigned int heap_wbuddy_calc_fblcount ( unsigned int  size,
unsigned int  m 
)

가중치 버디 시스템의 사용 가능 블록 리스트 수를 개산하는 함수

Parameters
size최대 멤버 수
m의미 없음
Returns
사용 가능 블록 리스트 수

0: 오류

◆ mallocn()

void* mallocn ( size_t  size)

기본 힙에서 정방향으로 메모리 블록을 할당하는 함수

Parameters
size요청 크기
Returns
할당된 메모리 블록의 주소

NULL: 오류

◆ mallocr()

void* mallocr ( size_t  size)

기본 힙에서 역방향으로 메모리 블록을 할당하는 함수

Parameters
size요청 크기
Returns
할당된 메모리 블록의 주소

NULL: 오류

◆ ubiclib_heap_comp_init()

int ubiclib_heap_comp_init ( unsigned int  addr,
unsigned int  size 
)

힙 컴포넌트를 초기화하는 함수

이 함수는 시스템 시작시 bsp 컴포넌트의 main 함수에서 자동적으로 호출됩니다.

Parameters
addr기본 힙으로 사용할 메모리의 주소
size기본 힙으로 사용할 메모리의 크기
Returns
0: 성공

-1: 오류
-n: n-1 번째 매개변수가 잘못되었음
HEAP_ERR__UNSUPPORTED: 지원하지 않음

◆ ubiclib_heap_comp_init_reent()

int ubiclib_heap_comp_init_reent ( void  )

힙 컴포넌트를 재진입(reenterance)이 가능하도록 초기화하는 함수

이 함수는 ubiclib_heap_comp_init 함수가 호출된 다음에 호출되어야 하며, 시스템 시작시 bsp 컴포넌트의 main 함수에서 자동적으로 호출됩니다.

Returns
0: 성공

-1: 오류
HEAP_ERR__UNSUPPORTED: 지원하지 않음