Memory and pointers

I need some help when we think about a task.

My task is to create one memory area

void *memory = malloc(320);

then use pointers to store texts in this storage location. We want to divide this area into 32 byte data blocks so that we can store: 320/32 = 10 data blocks - 32 bytes. In one data block I can store (1 ASCSII char = 1 byte) 32 characters.

I have a 10 bitmap where each bit indicates whether a data block is used (1) or not (0).

But what if I want to save text 60 characters long? Then I need 2 data blocks (2 x 32 bytes). The bitmap shows that data blocks 2 and 6 are free, 1 and 6 are not side by side. How can I achieve this?

struct  data {
    char * text;
};

typedef struct data d;

d->text = ???
+5
6

. , .

, #, ( - , ), ( ).

C:
, . - , , . , " " " " ..... , , , .

+4

, , ( ) - .

0

, -, , "" , .

0

:

  • /, ( , ). , , .

  • , , "" ( 31 ).

0

You can byte from each of 10 32 byte spaces and use this byte as an index to continue the line. This will be an actually linked list, and you can make it a doubly linked list by specifying indexes back and forth.

0
source

All Articles