Update SharedMemory initializer to accept type and size.
This commit is contained in:
parent
c320c75c8d
commit
ea063678cc
|
@ -7,7 +7,7 @@ module ProcessShared
|
||||||
class SharedMemory < FFI::Pointer
|
class SharedMemory < FFI::Pointer
|
||||||
include WithSelf
|
include WithSelf
|
||||||
|
|
||||||
attr_reader :size, :fd
|
attr_reader :size, :type, :type_size, :count, :fd
|
||||||
|
|
||||||
def self.open(size, &block)
|
def self.open(size, &block)
|
||||||
new(size).with_self(&block)
|
new(size).with_self(&block)
|
||||||
|
@ -21,13 +21,16 @@ module ProcessShared
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(size)
|
def initialize(type_or_count = 1, count = 1)
|
||||||
@size = case size
|
@type, @count = case type_or_count
|
||||||
when Symbol
|
when Symbol
|
||||||
FFI.type_size(size)
|
[type_or_count, count]
|
||||||
else
|
else
|
||||||
size
|
[:uchar, type_or_count]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@type_size = FFI.type_size(@type)
|
||||||
|
@size = @type_size * @count
|
||||||
|
|
||||||
name = "/ps-shm#{rand(10000)}"
|
name = "/ps-shm#{rand(10000)}"
|
||||||
@fd = RT.shm_open(name,
|
@fd = RT.shm_open(name,
|
||||||
|
|
Loading…
Reference in New Issue