Memory management in ScriptBasic

feastcanadianΛογισμικό & κατασκευή λογ/κού

14 Δεκ 2013 (πριν από 3 χρόνια και 10 μήνες)

85 εμφανίσεις

S

B

ScriptBasic

Memory Management

Introduction to ScriptBasic

Memory Management Module


S

B

Contents


Who is this
presentation for


Why memory
management is
important


How memory is
managed


Memory
management
structures


Memory
management
services


Top level
configure


S

B

Who this presentation is for


Curious (why things happen?)


Want to use the module outside
ScriptBasic


Want to modify ScriptBasic

NOT for those, who just


want to program in scriba



S

B

Why memory management is
important


ScriptBasic is not only a command
line tool


Memory leaking prevent long
running processes



Speed improvement is not aimed
at this level

S

B

How memory is managed

1/3


Separate, stand alone,
independent module


Can be compiled without any other
ScriptBasic module


General interface


Parameterized underlying OS mem
alloc/free functions



myalloc.c


S

B

How memory is managed

2/3


Memory is allocated from a logical
segment or


Memory is associated with a logical
segment

(matter of verbiage)


Segments can not loose memory


don’t loose segment (
testalloc.c

debug
layer)

S

B

How memory is managed

3/3


Segment is a double linked list with
head


Insert into front when memory is allocated


delete from list when released


release all is easy going through the linked
list


S

B

Memory management
structures

1/2


List head:

typedef struct _MyAlloc {


void * (*memory_allocating_function)(size_t);


void (*memory_releasing_function)(void *);



unsigned long MaxSize,CurrentSize;



pAllocUnit FirstUnit;


} MyAlloc, *pMyAlloc;

S

B

Memory management
structures

2/2


List member:

typedef struct _AllocUnit {


unsigned long Size; /* size of the chunk */


struct _AllocUnit *next; /* link to the next unit */


struct _AllocUnit *prev; /* the previous unit */


unsigned char memory[1]; /* one or more bytes reserved */


} AllocUnit, *pAllocUnit;



Note the alignment!

S

B

Memory management services


Alloc / Free on memory chunk
level


Init segment / Release segment


Merge segment

S

B

Top level configure


/etc/scriba/basic.conf


maxmem

XXXXX

(bytes)

S

B

Thank you for listening