関連するコードは次のとおりです。
typedef unsigned long int chunk_head;
typedef struct malloc_chunk
{
// Contains the size of the data in the chunk and the flag byte.
chunk_head head;
// Deliberately left unsized to allow overflow.
// Contains the payload of the chunk.
unsigned int data[];
};
例として、「get」マクロは次のとおりです。
//Get the size of the data contained within the chunk.
#define GET_CHUNK_SIZE(chunk) ((chunk.head) & 0xFFFFFF)
フラグのビットを使用している上位バイト-「使用中」と「合体可能」、および私が見つけた追加のものは役に立ちます。
タイトルで述べたように、背景情報の提供が完了したので、下位 3 バイトをチャンクの大きさに変更できるようにする必要があります。私の最初の本能は、ヘッダーとサイズをビットごとに AND することでした。これは、ヘッダーが適切に整列されるためです。しかし、フラグ バイトも上書きされる可能性があることに気付きました。ビットごとに int と long を ANDできるかどうかさえわかりません。とにかく、大歓迎です。