有一个任务是调用一个dll里面的函数,这个函数需要使用malloc来分配大量堆内存但是目前的问题是有很多进程调用这个dll,由于进程间堆是私有的,导致了每个进程都要去分配内存造成内存占用太大,所以想把这个dll改成com组件来解决这个问题,不知道com组件用malloc分配的内存对所有调用的进程都是共享的吗?如果是,这个内存是不是最先调用该com组件的进程分配的?谢谢.
调试欢乐多
你可以使用内存文件映射.来共享内存.这样所有实例使用的是同一段内存.
CreateFileMapping MapViewOfFileEx
allocator is not supported, E_INVALIDARG is returned. When supported, the
shared allocator returned by this function is an COM-provided implementation
of IMalloc interface, one which allocates memory in such a way that it can be
accessed by other process on the current machine simply by conveying the
pointer to said applications.2. Further, memory allocated by this shared
allocator in one application may be freed by the shared allocator in another.
Except when a NULL pointer is passed, the shared memory allocator never
answers -1 to IMalloc::DidAlloc; it always indicates that either did or did not
allocate the passed pointer.