-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshared_matrix_host.m
39 lines (35 loc) · 1.26 KB
/
shared_matrix_host.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
classdef shared_matrix_host < handle
properties (GetAccess = public, SetAccess = private)
Name
% HOST does not need to keep a data matrix (it's written to shared memory)
Handle
BasePointer
IsAttached
Platform
end
methods
function obj = shared_matrix_host(input_variable)
obj.Name = char(java.util.UUID.randomUUID);
obj.Platform = test_platform();
if obj.Platform == 0
error('SharedMatrix:NotSupported', 'Underlying MEX API not supported');
elseif obj.Platform == 1
obj.Name = ['Local\' obj.Name];
end
[obj.BasePointer, obj.Handle] = create_shared_matrix(obj.Name, input_variable);
obj.IsAttached = true;
end
function copy = attach(obj)
if ~obj.IsAttached
error('SharedMatrix:DataDetachedError', 'Shared memory has been detached');
end
copy = shared_matrix(obj.Name, obj.Platform);
end
function detach(obj)
if obj.IsAttached
obj.IsAttached = false;
delete_shared_matrix(obj.Handle, obj.BasePointer, [], obj.Name);
end
end
end
end