diff --git a/client.cpp b/client.cpp index 274fefa..22649c3 100644 --- a/client.cpp +++ b/client.cpp @@ -13,7 +13,7 @@ int main(int argc, char *argv[]) { try { - Server client(9049,"127.0.0.1",9048); + CNodeServer client(9049,"127.0.0.1",9048); vector fargs = {1,0,0,1}; vectorargs; CPart::addArg(&args, 12.63); diff --git a/cpart.h b/cpart.h index 366e762..f7cc39d 100644 --- a/cpart.h +++ b/cpart.h @@ -91,17 +91,16 @@ public: void Clear(void); // 在对象的传入参数列表中添加参数值 - template void addArgsIn(T value){ - T *p_value = new T(value); - if(p_value == nullptr) throw "fail to malloc"; + void AddCPArgsIn(void *arg){ + void *p_value = main_pool.b_get(arg); + if(p_value == nullptr) throw "information lost"; args_in.push_back(p_value); } + // 一般由lib文件中的计算模块调用的向vector中添加参数并分配内存空间而后初始化 - template - static void addArg(vector *args,T value){ - T *p_value = (T *) main_pool.b_malloc(sizeof(T)); - *p_value = value; - if(p_value == nullptr) throw "fail to malloc"; + static void addArg(vector *args, void *arg){ + void *p_value = main_pool.b_get(arg); + if(p_value == nullptr) throw "information lost"; args->push_back(p_value); } // 一般由lib文件中的计算模块调用的从vector中获得参数并释放其占用的内存空间而后返回相关值 @@ -117,7 +116,6 @@ public: p_value = main_pool.b_free(p_value); T value = *p_value; args->pop_back(); - return value; } }; diff --git a/memory.h b/memory.h index afd30b3..51f27ed 100644 --- a/memory.h +++ b/memory.h @@ -20,14 +20,17 @@ struct block_info{ }; class BlocksPool{ +// 内存块表 map blocks_list; public: +// 声明某内存块 void *b_malloc(uint32_t size){ void *ptr = malloc(size); if(ptr == nullptr) return nullptr; blocks_list.insert({ptr,{size,1}}); return ptr; } +// 标记使用某内存块 void *b_get(void *ptr){ auto blk = blocks_list.find(ptr); if(blk != blocks_list.end()){ @@ -36,6 +39,7 @@ public: } else return nullptr; } +// 标记保护某内存块 void b_protect(void *ptr){ auto blk = blocks_list.find(ptr); if(blk != blocks_list.end()){ @@ -43,6 +47,7 @@ public: } else throw "protect nil value"; } +// 标记不再保护某内存块 void b_noprotect(void *ptr){ auto blk = blocks_list.find(ptr); if(blk != blocks_list.end()){ @@ -50,6 +55,7 @@ public: } else throw "noprotect nil value"; } +// 标记不再使用某内存块 void b_free(void *ptr){ auto blk = blocks_list.find(ptr); if(blk != blocks_list.end() && blk->second.pted == false){