使用c++模拟增量垃圾收集
incremental garbage collection simulation using c++
我有一个项目,需要我模拟增量垃圾收集。该算法采用分代算法结合标记和扫描方法。到目前为止,我已经设计了一个结构,如所示的代码。问题在于为代码分配内存。我现在用的是向量。我还需要使用指针指向内存的开始和内存的结束。我不知道该怎么做。请一定要帮我设计这个。下面是我到目前为止的代码。
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <limits>
#include <stdio.h>
#include <sstream>
#include <vector>
using namespace std;
using std::stringstream;
string pMem, comment, sGen, val,input,id,size,inits,incs;
double pmemSize =0;
char t[10], m[256],init[10],inc[10];
struct rootset {
double totSize;
double *rStrtPtr;
double *rEndPtr;
vector<double> physicalM; /* This is the size of physical memory i need to assign*/
struct generations {
double totSize;
const char *genStrtPtr;
const char *genEndPtr;
int numOfGen;
string genName;
struct object {
double objSize;
const char *objStrtPtr;
const char *objEndPtr;
string id;
char markBit;
char objPtr;
};
struct freeList {
double freeSpace;
int flNumb;
};
};
};
int main()
{
int pmemSize;
cout<<" ENter the size "<<endl;
cin >> pmemSize;
vector<rootset> pRootSet;
pRootSet.push_back(rootset());
pRootSet[0].totSize = pmemSize;
pRootSet[0].physicalM.reserve(pmemSize);
for (int s=0; s<pmemSize; ++s)
pRootSet[0].physicalM.push_back(s);
vector<double>::iterator it;
for(it = pRootSet[0].physicalM.begin(); it!= pRootSet[0].physicalM.end(); ++it)
cout <<"Printing it: " <<(*it)<<endl;
}
我现在的问题是如何指向指针*rStrtPtr和*rEndPtr;到物理内存的第一个位置…?详细信息:用户输入要为模拟保留的物理内存量。它的单位是字节。为了简单起见,我只使用int。稍后我将把它更改为双倍,因为分配可以增加到1gb。我创建了一个名为physicalM的向量。这是实际的物理内存块。稍后将划分为几代(由子结构代表示)。当用户指定命令(abc = alloc(50B));
时,我必须在较低的代中创建一个名为abc的对象,并为其分配50MB的大小。(这部分我会在后面讨论)。任何帮助都很感激……
pRootSet[0].rStrtPtr = &(pRootSet[0].physicalM);
error: cannot convert ‘std::vector<double>*’ to ‘double*’ in assignment
Edit:修复必须将rStrtPtr初始化为vector
pRootSet[0].rStrtPtr = &(pRootSet[0].physicalM);
应该读:
pRootSet[0].rStrtPtr = &(pRootSet[0].physicalM[0]);
或
pRootSet[0].rStrtPtr = pRootSet[0].physicalM.data();
或
pRootSet[0].rStrtPtr = &*(pRootSet[0].physicalM.begin());
pRootSet[0].rEndPtr = &*(pRootSet[0].physicalM.end()); // this will point to the first byte AFTER the end of the buffer.
我不知道为什么你在double
中存储数据大小。一个unsigned long
可以存储2^32 - 1(4294967295),即4GB
相关文章:
- 如何使用Google Mock来模拟gettimeofday()
- G锁定铸造到基础上会释放模拟行为
- 有什么好的方法可以让系统调用代理允许在单元测试中进行模拟
- 落砂模拟碰撞检测C++和SFML
- 在gtest.中使用fff.h模拟系统API
- 谷歌模拟和覆盖关键字
- 用C#中的并集模拟C++嵌套结构
- 在同一模拟中使用静脉和静脉_ inet内容时出现运行时错误
- 在模拟器中使用并集来模拟CPU寄存器有多合适
- 我写了一个C++程序来模拟Enigma机器.我没有得到输出
- 如何模拟不同边数的骰子滚动?
- 模拟持久按键
- 使用SIR模型的疾病爆发模拟
- 在 c++ 中模拟输入并在 JAVA 中读取它?
- 转发变量参数列表以模拟 std::thread
- 如何在谷歌模拟中匹配 C 样式数组
- 如何使用兰德随机化模拟点击
- 模拟GPS数据,以便使用Qt与Traccar一起使用
- QKeyPress - 在Qt中模拟按键
- 如何使用不同的谷歌模拟运行相同的谷歌测试用例?