Search code examples
cmemoryblockmemcpy

Delete struct written with memcpy


I have an assignment on memory blocks. We have a struct Record that I need to save in these memory blocks. Each block holds 5 Records, which i memcpy one after another in a list of blocks and an int CountOfRecords.

We also have a DeleteRecord function that deletes (duh) a particular record from the memory block. Now, other than reducing the Count and shifting all next Records forward as to practically delete that Record, is there any way to ACTUALLY delete what is written with memcpy? Like writing something like a NULL as a struct instance? Memmove does not seem to offer such an application.

EDIT: I write the records as such

//block is the pointer to block,int is for the Count, and record is placed
memcpy(block+sizeof(int)+sizeof(Record),&record,sizeof(Record));

Solution

  • You basically don't want to move data around but instead set the memory to zero, how about memset?

    memset(block+sizeof(int)+sizeof(Record), 0, sizeof(Record));
    

    But you somehow have to remember, that the record at this point is zeroed out (not used), best by some property.