공유메모리를 쓰는 프로그램을 만들려고 하는데요, 공유메모리상에 연결리스트를 구현하려고 합니다. 당연히 노드를 할당할 때 malloc 같은 것은 쓸 수 없겠죠? 혹시 공유메모리 상에서 동작하는 malloc같은 함수가 있나요? 아니면 이런 경우 메모리 관리 함수를 직접 만들어야 하나요????
typedef struct _t_linkedLst { struct _t_linkedLst *next; struct _t_linkedLst *prev;
t_dataType data; } t_linkedLst;
t_dataType 이란 구조체를 연결리스트로 만든다고 가정합니다.
t_linkedLst (*list)[MAX_LINKED_LIST]; t_linkedLst head, unused;
위와 같이 선언해서,
list 에 공유메모리 주소를 할당해 줍니다.
처음에 unused 에 (*list) 배열로 선언한 각 자료들을 모두 연결리스트로 붙여 주고,
malloc 이 필요할 때는 unused 에서 하나를 떼어서 head 에 붙이고 free 를 할 때는 head 에서 떼어서 unused 에 붙여 주시면 됩니다.
이런식으로 배열을 미리 선언해 놓고, 안 쓰는 놈, 쓰는 놈을 구분해서 마치 malloc 하고 free 하는 것 처럼 구현하시면 됩니다.
Perfection (in design) is achieved not when there is nothing more to add, but rather when there is nothing more to take away.
텍스트 포맷에 대한 자세한 정보
<code>
<blockcode>
<apache>
<applescript>
<autoconf>
<awk>
<bash>
<c>
<cpp>
<css>
<diff>
<drupal5>
<drupal6>
<gdb>
<html>
<html5>
<java>
<javascript>
<ldif>
<lua>
<make>
<mysql>
<perl>
<perl6>
<php>
<pgsql>
<proftpd>
<python>
<reg>
<spec>
<ruby>
<foo>
[foo]
배열로 선언하고 사용할 수 있습니다.
typedef struct _t_linkedLst
{
struct _t_linkedLst *next;
struct _t_linkedLst *prev;
t_dataType data;
} t_linkedLst;
t_dataType 이란 구조체를 연결리스트로 만든다고 가정합니다.
t_linkedLst (*list)[MAX_LINKED_LIST];
t_linkedLst head, unused;
위와 같이 선언해서,
list 에 공유메모리 주소를 할당해 줍니다.
처음에 unused 에 (*list) 배열로 선언한 각 자료들을 모두 연결리스트로 붙여 주고,
malloc 이 필요할 때는 unused 에서 하나를 떼어서 head 에 붙이고
free 를 할 때는 head 에서 떼어서 unused 에 붙여 주시면 됩니다.
이런식으로 배열을 미리 선언해 놓고, 안 쓰는 놈, 쓰는 놈을 구분해서 마치 malloc 하고 free 하는 것 처럼 구현하시면 됩니다.
Perfection (in design) is achieved not when there is nothing more to add, but rather when there is nothing more to take away.
댓글 달기