www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Class member function with a Callback funtion parameter

reply Herbert <ht softdesign.de> writes:
My project does not allow dynamic memory. So I can't use 
delegates.

How can I declare a class member function with a callback 
function pointer?
Jan 27 2020
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Monday, 27 January 2020 at 21:21:55 UTC, Herbert wrote:
 My project does not allow dynamic memory. So I can't use 
 delegates.
delegates do not require dynamic memory. &obj.member doesn't allocate any new memory (it just points to the existing object) yet yields a delegate.
Jan 27 2020
parent reply Herbert <ht softdesign.de> writes:
On Monday, 27 January 2020 at 21:51:35 UTC, Adam D. Ruppe wrote:
 On Monday, 27 January 2020 at 21:21:55 UTC, Herbert wrote:
 My project does not allow dynamic memory. So I can't use 
 delegates.
delegates do not require dynamic memory. &obj.member doesn't allocate any new memory (it just points to the existing object) yet yields a delegate.
As I understand the D language documentation says: delegates sometimes use dynamic memory.
Jan 27 2020
parent reply "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Mon, Jan 27, 2020 at 10:13:47PM +0000, Herbert via Digitalmars-d-learn wrote:
 On Monday, 27 January 2020 at 21:51:35 UTC, Adam D. Ruppe wrote:
 On Monday, 27 January 2020 at 21:21:55 UTC, Herbert wrote:
 My project does not allow dynamic memory. So I can't use
 delegates.
delegates do not require dynamic memory. &obj.member doesn't allocate any new memory (it just points to the existing object) yet yields a delegate.
As I understand the D language documentation says: delegates sometimes use dynamic memory.
Only if you're using a lambda or a delegate that captures local variables. T -- Fact is stranger than fiction.
Jan 27 2020
parent Herbert <ht softdesign.de> writes:
On Monday, 27 January 2020 at 22:20:42 UTC, H. S. Teoh wrote:
 On Mon, Jan 27, 2020 at 10:13:47PM +0000, Herbert via 
 Digitalmars-d-learn wrote:
 On Monday, 27 January 2020 at 21:51:35 UTC, Adam D. Ruppe 
 wrote:
 On Monday, 27 January 2020 at 21:21:55 UTC, Herbert wrote:
 My project does not allow dynamic memory. So I can't use 
 delegates.
delegates do not require dynamic memory. &obj.member doesn't allocate any new memory (it just points to the existing object) yet yields a delegate.
As I understand the D language documentation says: delegates sometimes use dynamic memory.
Only if you're using a lambda or a delegate that captures local variables. T
Chapter "Memory Management": "D has built-in types that may be difficult to use without the GC: exceptions, strings, dynamic arrays, associative arrays, and delegate closures." I would like to do something like this: interface Timer { void delegate pCallbackFunction(void); this(); void Start(ushort milliseconds, pCallbackFunction); void Halt(); void Restart(); }
Jan 27 2020