I'm trying to initialize some values in couple of structs I created. (the goal of the program is to simulate virtual memory) For some reason when I try to initalize pgTable[i].validFlag = 1
I get this error:
malloc(): corrupted top size
but not if I initialize it to 0. I thought this had something to go with me going off the end of my array but I don't see how that's possible.
Can anyone tell me what I'm doing wrong?
int* memmory = malloc( sizeof( int ) * sizeVM * pageSize );
struct TLBentry* tlb = malloc( sizeof(struct TLBentry) * sizeTLB );
struct pageTableEntry* pgTable = malloc( sizeof(struct pageTableEntry) * sizeVM );
for( int i = 0; i < sizeTLB; i++){
tlb[i].virtualAddress = i;
tlb[i].physicalAddress = i;
}
for( int i = 0; i < sizePM; i++){
pgTable[i].dirty = 0;
pgTable[i].validFlag = 1;
pgTable[i].physicalAddress = i;
}
memSys->virtMem = memmory;
memSys->tlb = tlb;
memSys->pgTable = pgTable;
The most likely causes are writing outside the bounds of an allocated object, or writing to an object after it has been deleted. These errors can be difficult to track down with a debugger.
A double free or corruption likely means that free was called twice on the same block of memory, or that something was overwritten that shouldn't have been, e.g. an array overrun or something similar. This might have happened deep within Julia itself or in some C library that your code calls.
Your loop goes up to sizePM
while you allocate sizeVM
entries.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With