Add free() wrapper for proper memory management

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Add free() wrapper for proper memory management

Pieter-Jan Briers
Hi,

The documentation for fluid_settings_dupstr() says to use free() to free
the string given by the function. I am trying to use the library from
C#, and while .NET does have equivalents to malloc/free, there is no
guarantee this matches the free() used by Fluidsynth. (At least with
Linux CoreCLR it seems to, but especially on Windows this can easily get
murky)

The result is that I am basically forced to leak the string given to me
by fluid_settings_dupstr(), since I cannot correctly call free() as used
by Fluidsynth.

Would it be possible to provide something along the lines of
fluid_free(), which would simply be a wrapper to free()?

Thank you,

Pieter-Jan Briers


_______________________________________________
fluid-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/fluid-dev
Reply | Threaded
Open this post in threaded view
|

Re: Add free() wrapper for proper memory management

Ceresa Jean-Jacques

Hi,

 

>I am trying to use the library from C#,....

I guess you use the fluidsynth shared library, and you have a way to bind your C# code to C fluidsynth API.

In this case you could write and build a new C shared library that contains the C functions you need.

For example, let the following new C shared library source for your need:

 

On Windows,

1) make a new project: shared C library.

2) put the the following code in your new project

 

/*

 *   The function free memory using free().

*/

__declspec(dllexport) fluid_free( void * p)

{

    free(p)

}

 

3) build your new shared C project.

4) Than from your C# project, (4.1) call fluid_free() (the same way you call any fluidsynth API), and then (4.2) bind your new shared library (the same way you bound fluidsynth shared library).

jjc

 


_______________________________________________
fluid-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/fluid-dev
Reply | Threaded
Open this post in threaded view
|

Re: Add free() wrapper for proper memory management

Pieter-Jan Briers
In reply to this post by Pieter-Jan Briers
Hi,

 > In this case you could write and build a new C shared library that
contains the C functions you need.

I could do this, but this would require an extra shared library which
would be a pain to manage. Ideally I really shouldn't need any extra
native binaries outside of a normal libfluidsynth.so (or whatever
platform specific name is).

Also, as far as I can tell, this approach is still not a proper solution
on Windows, since modules may have their own heaps (so the glue library
could have a different heap than Fluidsynth), see
https://stackoverflow.com/a/36420475/4678631 . I would either have to
static link or (easier) fork Fluidsynth to add this myself.


_______________________________________________
fluid-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/fluid-dev
Reply | Threaded
Open this post in threaded view
|

Re: Add free() wrapper for proper memory management

fluid-dev mailing list
Pieter is raising a good point. Exposing a fluid_free() is no problem.

Just let me know pls.: Are you using fluidsynth from recent git or
some stable release? Because if you are using recent git anyway, I
would just commit the change to master and not release a 2.0.7 for the
moment.

Tom

_______________________________________________
fluid-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/fluid-dev
Reply | Threaded
Open this post in threaded view
|

Re: Add free() wrapper for proper memory management

Pieter-Jan Briers
In reply to this post by Pieter-Jan Briers
I'm just using the build from the Arch repos right now, but I don't have
a problem with building it from source to test this (in fact, I already
did to debug something).

Pieter-Jan Briers


_______________________________________________
fluid-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/fluid-dev
Reply | Threaded
Open this post in threaded view
|

Re: Add free() wrapper for proper memory management

Ceresa Jean-Jacques
In reply to this post by Pieter-Jan Briers

>Also, as far as I can tell, this approach is still not a proper solution on Windows, since modules may have their own heaps....

Comfirmed, this is a bad approch. I had stumbled on the same problem in the past; I forgot about that !

Thanks for raising this.

jjc


_______________________________________________
fluid-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/fluid-dev
Reply | Threaded
Open this post in threaded view
|

Re: Add free() wrapper for proper memory management

fluid-dev mailing list
PR opened, to be merged soon.

https://github.com/FluidSynth/fluidsynth/pull/562

Tom



_______________________________________________
fluid-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/fluid-dev
Reply | Threaded
Open this post in threaded view
|

Re: Add free() wrapper for proper memory management

fluid-dev mailing list
FYI: #562 was merged and will be part of 2.0.7 . There currently is an
issue with the dsound driver on windows, so the release of 2.0.7 needs
to wait.

Tom

_______________________________________________
fluid-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/fluid-dev
Reply | Threaded
Open this post in threaded view
|

Re: Add free() wrapper for proper memory management

fluid-dev mailing list
Hello,
excuse me, what is the issue with the dsound driver?

Sincerely.

> Il 27 settembre 2019 alle 9.11 "Tom M. via fluid-dev" <[hidden email]> ha scritto:
>
>
> FYI: #562 was merged and will be part of 2.0.7 . There currently is an
> issue with the dsound driver on windows, so the release of 2.0.7 needs
> to wait.
>
> Tom
>
> _______________________________________________
> fluid-dev mailing list
> [hidden email]
> https://lists.nongnu.org/mailman/listinfo/fluid-dev

_______________________________________________
fluid-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/fluid-dev
Reply | Threaded
Open this post in threaded view
|

Re: Add free() wrapper for proper memory management

Ceresa Jean-Jacques
In reply to this post by Pieter-Jan Briers

> Hello, excuse me, what is the issue with the dsound driver?

No, dsound driver is fine and works well. Simply a bug was introduced by changes on reverb initialization. This bug caused a side effect on audio output.

The culprid wasn't dsound driver but this wrong reverb initialization. This bug was fixed by Tom in commit 44453FF.

jjc.

 


_______________________________________________
fluid-dev mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/fluid-dev