Guest User

Untitled

a guest
Apr 25th, 2012
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. Void * space in a struct instead of malloc
  2. typedef struct Entry {
  3. int counter;
  4. void *block;
  5. } Entry;
  6.  
  7. void *memPtr = mmap(NULL, someSize*1024, PROT_READ|PROT_WRITE,
  8. MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
  9.  
  10. int AddEntry(void *data) {
  11. Entry entry;
  12. entry.counter = 1;
  13. entry.block = malloc(sizeof(char *) * SECTOR_SIZE);
  14. memcpy(entry.block, data, SECTOR_SIZE);
  15. memcpy(&memPtr[0], &entry, sizeof(Entry));
  16. return 0;
  17. }
  18.  
  19. int AddEntry(void *data) {
  20. Entry *entry;
  21. entry = malloc(sizeof(Entry) + ((SECTOR_SIZE-1) * sizeof(unsigned char));
  22. // obligitory NULL checks assumed here
  23.  
  24. // fill in structure
  25. entry->counter = 1;
  26. memcpy(entry->block, data, SECTOR_SIZE);
  27. memcpy(&memPtr[0], &entry, sizeof(Entry) + ((SECTOR_SIZE-1) * sizeof(unsigned char));
  28. return 0;
  29. }
  30.  
  31. block
Advertisement
Add Comment
Please, Sign In to add comment