In C, implement a tagged memory system. Create a system where memory allocation
ID: 3910810 • Letter: I
Question
In C, implement a tagged memory system.
Create a system where memory allocation could be created via string tags. More than 1 allocation may be associated with a single tag. The system has five functions.
tag_create - Create the system for allocating and tagging memory.
tag_destroy - Destroy the tagged memory system.
tag_malloc - Allocate memory from the heap and associate it with a string tag.
tag_free - Free memory previously allocated with tag_malloc.
tag_get_tag - Get the associated tag string from a memory block previously allocated by tag_malloc and not yet freed by tag_free
Explanation / Answer
1. tag_create ->> Function
char *tagCreate()
{
char *str = "GfG"; /* Stored in read only part of shared segment */
return str;
}
int main()
{
printf("%s", tagCreate());
getchar();
return 0;
}
2. tag_destroy -> Destroy the created tag
tag_malloc ->>
tag_free --> To free memory
tag_get_tag -->
We are requested to answer a minimum of 4 options from a given question..
Thank you