In my project, I need to use a fixed key not a generated key.
So I wanna suggest to change create method like following.
I added defkey parameter.
When it is not defined, the key would be generated as it was.
But if it is given, the key would be set defkey value.
/**
* Create shared memory segment
* @param {int} count - number of elements
* @param {string} typeKey - see keys of BufferType
* @param {int} defkey - default key
* @return {mixed} shared memory buffer/array object
* Class depends on param typeKey: Buffer or descendant of TypedArray
* Return object has property 'key' - integer key of created shared memory segment
*/
function create(count, typeKey, defkey) {
if (typeKey === undefined)
typeKey = 'Buffer';
if (BufferType[typeKey] === undefined)
throw new Error("Unknown type key " + typeKey);
var type = BufferType[typeKey];
if (!(Number.isSafeInteger(count) && count >= lengthMin && count <= lengthMax))
throw new RangeError('Count should be ' + lengthMin + ' .. ' + lengthMax);
let key, res;
do {
if (defkey === undefined)
key = _keyGen();
else
key = defkey;
res = shm.get(key, count, shm.IPC_CREAT|shm.IPC_EXCL|perm, 0, type);
} while(!res);
res.key = key;
return res;
}
Hi.
Thank to develop and open this module.
In my project, I need to use a fixed key not a generated key. So I wanna suggest to change create method like following. I added defkey parameter. When it is not defined, the key would be generated as it was. But if it is given, the key would be set defkey value.