Newbie here, sorry if this is basic!
I am writing some C modules to integrate with some other pre-written libraries I have for my board, and would be grateful for any advice for how best to approach this.
I have external libraries which produce and consume a large amount of data - so one library produces a large chunk of data, which other libraries can consume, and in C++ this is just done by passing around pointers. I'm trying to write wrappers for these, so the process can be directed by a MicroPython script, something along the lines of:
Code: Select all
chunk = lib1.create_data()
lib2.process_data(chunk)
1) If the Python script doesn't need to access the individual bytes of the data chunk, can I avoid copying the data into and out of MicroPython's heap? Could I maybe package up the data chunk as a "bytes" object while it is outside of MicroPython's heap, or will this cause complications with the garbage collector? Or is there a common way to have a "reference" to an external chunk of memory I should be looking at?
2) If I do have a way to reference this external chunk of memory, I'd like to be able to free it as soon as the Python script is done with it. Is there any way I can do this without waiting for a garbage collection sweep? (I was thinking of something like watching the reference count of the object, but I'm not sure that's how MicroPython manages memory..?) Or is the best solution to add an explicit API to the chunk object which the script could use to signal it is finished with it?
Again sorry if this is a common scenario I haven't yet found in the docs / forums! Many thanks for any advice.