Memory Allocation

Smart people out there,

I need your help. I have basic knowledge about C++ first of all.
I got a task to make a simulation of a memory allocation using the next-fit memory allocation strategy.
The code should be able to simulate how next-fit works with some requirements:

1. Data should be in a form of data stream.
2. The memory consists of 256 blocks with 256 KB size each.

Can someone help me with this? I have no idea how to simulate streams of data in C++. Thanks.

Audric Nathan

if its just a simulation, you can actually just do the tracking without doing the memory allocation and management at all. Just track what you WOULD do. This is much easier. Is that all you need, is the simulation??
Then you just need to keep track of what memory is in use, and what is not, and then fit new items into what is free.


I forgot to say that it will be a simulation to store data stream to a flash chip.
So far I made the initialization of the flash chip, defining the size of it and creating a write and delete process.
But I am still confused on how to create a simulation of the data stream itself and how to show it.
something on these lines?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <memory>
#include <vector>
#include <utility>

constexpr size_t streamSize = 256 * 256 * 256;
constexpr auto SIZE = 256;

int main()
{
    std::vector<std::unique_ptr<char[]>> nextFit{};
    for (size_t i = 0; i < SIZE; ++i)
    {
        nextFit.push_back(std::move(std::make_unique<char[]>(streamSize)));
    }
}
Topic archived. No new replies allowed.