jemc changed the topic of #ponylang to: Welcome! Please check out our Code of Conduct => https://github.com/ponylang/ponyc/blob/master/CODE_OF_CONDUCT.md | Public IRC logs are available => http://irclog.whitequark.org/ponylang | Please consider participating in our mailing lists => https://pony.groups.io/g/pony
jemc has quit [Ping timeout: 240 seconds]
ro6 has joined #ponylang
Matthias247 has quit [Read error: Connection reset by peer]
jmiven has quit [Quit: co'o]
jmiven has joined #ponylang
jemc has joined #ponylang
amclain has quit [Quit: Leaving]
ro6 has quit [Quit: Connection closed for inactivity]
jemc has quit [Ping timeout: 240 seconds]
puzza007 has quit [Quit: Connection closed for inactivity]
flippant has quit [Ping timeout: 240 seconds]
SparkySparkyBoom has joined #ponylang
rurban has joined #ponylang
prettyvanilla has quit [Ping timeout: 255 seconds]
_andre has joined #ponylang
Candle has joined #ponylang
<kempe> Hello! I've been interested in pony for a while and was thinking of trying it out for a project I have in mind. One quirk is that I have to pass binary data to and from functions written in C (I'm hooking some custom networking related kernel things) and I'm wondering if there is a best practice for doing this. I saw the the Array type has a function called from_cpointer, but I assume that memory management
<kempe> would have to be done on the C side of things since it states it doesn't copy the data?
<SeanTAllen> if the memory is allocated by c, then yes, by default you would need to free it yourself
<kempe> Is there some way to copy the data returned to pony so that I can use a local stack variable in C and let that one fall out of scope and let pony's GC handle the memory management on the pony side? I'd rather avoid manual memory management as much as possible
<SeanTAllen> yes but you will still need to free the original memory
<kempe> Although that would be done automatically if I don't use malloc, but a stack variable local to the function in C I'm calling, right?
<kempe> When the function ends and the variable goes out of scope
<SeanTAllen> if you wanted an array for example, i would suggest checking out the "from_cpointer" constructor that is part of Array
<kempe> I did have a look at that one, but since it states that the data is not copied I assume I can't use a local variable C side since the variable the pointer is reffering too can't go out of scope until the pony code is done with it? That is I'd have to use malloc when getting the data and make sure to have a C function calling free on the memory when pony's GC reclaims the Array. Or does pony automatically
<kempe> free the memory of the pointer used in from_cpointer when the Array is GC'ed?
<SeanTAllen> right in the case of from_cpointer then you wouldnt be freeing that memory, it would be handled for you
<SeanTAllen> actually im not sure of that
<kempe> Nice! Then that works perfectly. Thank you!
<SeanTAllen> don't trust me on that. i'm under the weather today.
<kempe> No worries, at least I have a starting point. I'll play around a bit and see how it works out
<kempe> I must say I am crushing a bit on pony at the moment :P
<SeanTAllen> we have a product that has a C++ API and memory is allocated in C++ but we need to free at some point from pony
<SeanTAllen> we create a CPPData object to wrap that memory and when it is freed, we have a finalizer on CPPData that will free the underlying memory
<kempe> Okay, I see. I guess I might have to wrap the array in another object that calls a free function in C from its final member function
<SeanTAllen> it's what we do so the person using the C++ API doesn't have to worry about when the memory needs to be freed
<kempe> Okay, sounds reasonable
<SeanTAllen> One of our requirements for our C++ API was "end developer shouldnt have to manually manage memory"
<kempe> A wise requirement as most crashes, in my experience, are caused by memory handling errors
<SeanTAllen> another option, kempe, if you have control of the c code is to use pony_alloc to allocate the memory.
<SeanTAllen> if you want to use "from_cpointer", you can use that then clone the array, the free the C pointer using FFI
wizeman has joined #ponylang
<kempe> I'm not familiar with pony_alloc. Should I read the source for pony or is it documented somewhere?
<SeanTAllen> its part of the c runtime
<kempe> Looks interesting. If I call an FFI-function can I simply use the pony_ctx()-call to get the correct context for allocating GC'ed memory?
jemc has joined #ponylang
jemc has quit [Ping timeout: 260 seconds]
<SeanTAllen> i believe so yes
<kempe> Thank you for you help. I know where to start now and I'll do some experimenting
<SeanTAllen> you're welcome kempe
rurban has quit [Quit: Leaving.]
aav has joined #ponylang
jemc has joined #ponylang
amclain has joined #ponylang
inara` has quit [Quit: Leaving]
inara has joined #ponylang
rurban has joined #ponylang
rurban1 has joined #ponylang
rurban has quit [Ping timeout: 268 seconds]
prettyvanilla has joined #ponylang
rurban1 has quit [Quit: Leaving.]
rurban has joined #ponylang
rurban has quit [Client Quit]
wizeman has quit [Quit: Connection closed for inactivity]
Matthias247 has joined #ponylang
<omarkj> Had no idea stable existed. Great work jemc. Has come in really handy compared to manually managing these.
<SeanTAllen> its a great impediment to a full package manager ;)
<SeanTAllen> its met all our needs at Sendence so far (we had a couple small changes we PR'd in but otherwise, so simple, so good)
<SeanTAllen> from time to time, i think "I should open an RFC to make stable the official package manager"
<omarkj> I saw the long github thread since 2015 about a package manager.
<SeanTAllen> lol
<SeanTAllen> yes
<omarkj> Wondering where that was at, if anywhere, with the core team.
<SeanTAllen> i think the problem is... that most of the folks we are using Pony all the time, are fine with stable
<SeanTAllen> no one has an itch to scratch on that front
<SeanTAllen> if there were many libraries and discovery was hard, i think something like cargo would have more uptake
<omarkj> Right, maybe it's just too early to look into a cargo-like software?
<omarkj> Cargo has some nice features like compile flags for dependencies, etc.
<omarkj> But I haven't used Pony enough to say if something like that is really useful when you're in it full time :)
<SeanTAllen> So far, we haven't needed. But that is just for our Sendence use case.
rurban has joined #ponylang
_whitelogger_ has joined #ponylang
_whitelogger has quit [Remote host closed the connection]
_andre has quit [Quit: leaving]
rurban1 has joined #ponylang
rurban has quit [Ping timeout: 260 seconds]
andreaa has quit [Ping timeout: 276 seconds]
andreaa has joined #ponylang
SparkySparkyBoom is now known as flippant