'Is there a kernel call to insert a block of memory?
Insertion of k bytes into a block of memory of length n would be O(n) because all the bytes after must be moved further back. Data structures like trees and linked lists attempt to solve this problem but at a cost since the pointers are also overhead.
However, if the number of bytes to be inserted is large, on the order of page size, then it seems to me the memory manager could be used.
Suppose I am using C, and willing to call whatever function necessary to allocate the memory. Is there any way to insert a block of say, 4k, by getting the memory manager to redefine the page structure inserting a 4k block in the middle of the large chunk without actually moving any memory?
char* m = allocate_memory(n);
insertblock(m, offset, 4096);
free_memory(m);
in such a way that the cost is not O(n)?
Would there be a way to do more than one at the same time? For example, to insert 3 blocks of 4k each at 1M, 2M and 3M
int offsetlist[3] = {1024*1024, 2*1024*1024, 3*1024*1024};
insertmultipleblocks(m, offsetlist, size);
last, is there anything in Windows to achieve the same goal so this code can be made portable?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
