How To Resize A Shared Memory In Python
I want to use an array for shared memory. The problem is the program is structured in such a way that the child processes are spawned before I know the size of the shared array. If
Solution 1:
try :
unshared_Arr = mp.Array(ctypes.c_uint8,SIZE_NEEDED) #should be size #and not the array itself
np_shared = np.frombuffer(ushared_Arr.get_obj(),dtype=ctypes.c_uint8)
np_shared.reshape(SIZE_NEEDED/2,SIZE_NEEDED/2) #or (,SIZE_NEEDED) ie. any shape #you want as long as the allocated size #does not change
now use np_shared as you would any numpy array. You should keep it global if multiple processes are going to need it.
Post a Comment for "How To Resize A Shared Memory In Python"