From: Anthony Halley on 8 Jun 2010 09:42 > classdef myclass < handle > properties (Hidden = true, SetAccess = private) > cpp_handle; > end > methods > % Constructor > function this = myclass() > this.cpp_handle = init_mex(); > end > % Destructor > function delete(this) > clear_mex(this.cpp_handle); > end > % Example method > function output = action(this, data) > output = action_mex(this.cpp_handle, data); > end > end > end Thank you Oliver. I have a couple more questions if you have a second: What are you returning from init_mex()? Is that a pointer to a C++ class instance? If so, how are you allocating the memory, are you using "new" or "mxMalloc"?
From: Anthony Halley on 8 Jun 2010 09:47 Please excuse the double-post, sorry about that.
From: Oliver Woodford on 8 Jun 2010 10:41 "Anthony Halley" wrote: > What exactly are you returning from init_mex()? Is that a pointer to a C++ class instance? Are you using "new" or "mxMalloc" to allocate the memory for that instance? I haven't gotten round to implementing it myself, but I plan to return a pointer to a C++ class instance (cast as a uint64), with memory allocated using "new". MATLAB will call the myclass delete function when it clears the pointer, so the only time this wouldn't happen is if MATLAB crashed. However, in that case I'd hope that the OS' memory management system would free all the memory associated with that thread, including the memory allocated by "new".
First
|
Prev
|
Pages: 1 2 Prev: OOP: constructing an array of object for a subclass Next: drawing on an image in a GUI |