Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Void * space in a struct instead of malloc
- typedef struct Entry {
- int counter;
- void *block;
- } Entry;
- void *memPtr = mmap(NULL, someSize*1024, PROT_READ|PROT_WRITE,
- MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
- int AddEntry(void *data) {
- Entry entry;
- entry.counter = 1;
- entry.block = malloc(sizeof(char *) * SECTOR_SIZE);
- memcpy(entry.block, data, SECTOR_SIZE);
- memcpy(&memPtr[0], &entry, sizeof(Entry));
- return 0;
- }
- int AddEntry(void *data) {
- Entry *entry;
- entry = malloc(sizeof(Entry) + ((SECTOR_SIZE-1) * sizeof(unsigned char));
- // obligitory NULL checks assumed here
- // fill in structure
- entry->counter = 1;
- memcpy(entry->block, data, SECTOR_SIZE);
- memcpy(&memPtr[0], &entry, sizeof(Entry) + ((SECTOR_SIZE-1) * sizeof(unsigned char));
- return 0;
- }
- block
Advertisement
Add Comment
Please, Sign In to add comment