c - malloc pointer identification -
Then I have to apply it to my own malloc and free to do this job. The problem is a So my memory structure is this: I have a global indicator to start the array, which I am working on. Each block of memory has a This is my memory_free (zero * ptr) function right now, TYPE is Indicator < Code> ptr indicates the first byte of the user, which means that if I want to read the header, I will have to go back to 4 bytes. To solve the validity of the indicator, a solution heap from the beginning To go through and to see if I get to the headers in question, but it is not time efficient How can I tell? One O (1) solution will make header 8 bytes instead of four Use additional four bytes to indicate validity, for example, it may be in the form of supplement to whatever you store in the other four bytes, so if you look at the header and if those extra bytes In addition to complementing the first part of the header, you know that There is not a valid block. memory_free (zero * PTR) function. If the pointer is invalid, then it must be returned to 1, i.e. it is not allocated by
memory_alloc (unsigned integer size) , or 0 returns otherwise. I can not understand a way to do this without being completely disabled.
int header to tell its size and whether it is free or not.
typedef unsigned int :
int memory_free (zero * ptr) { Zero * head = ptr; If (head == faucet) 1 return; Head - size = (TYPE); If (! (* (TYPE *) head) and 1) return 1; (* (TYPE *) head) & amp; = ~ 0x1; return 0;}
Comments
Post a Comment