Search found 598 matches

by stijn
Thu Apr 22, 2021 5:56 pm
Forum: General Discussion and Questions
Topic: Help interfacing with C function and input parameters format
Replies: 7
Views: 1596

Re: Help interfacing with C function and input parameters format

That's a matter of preference. In C and C++ it's not bad to make everything possible const, but in this case it is not ideal since mp_obj_t can be a pointer, but not always (depending on platform). So it gives a mixed feeling of safety. I.e. if it's a pointer then it only guards you from writing *ar...
by stijn
Thu Apr 22, 2021 3:16 pm
Forum: General Discussion and Questions
Topic: Help interfacing with C function and input parameters format
Replies: 7
Views: 1596

Re: Help interfacing with C function and input parameters format

why we need to use const mp_obj_t arg1 Can you give an example of where that is required? float features[]; This is probably wrong (does this even compile?): mp_obj_get_array takes an mp_obj_t** as last argument, not a float*. Even if it doesn't cause undefined behavior, it might not get you the fl...
by stijn
Tue Apr 20, 2021 6:54 am
Forum: General Discussion and Questions
Topic: Valgrind Results
Replies: 7
Views: 235

Re: Valgrind Results

Upon a closer look it turns out all of these essentially come down to valgrind thinking that the global mp_state_ctx.mem.xxx values are not initialized, which is demonstrably false because one of the first things done in main() is calling gc_init() which initializes all of that. So unless I'm missin...
by stijn
Tue Apr 20, 2021 6:17 am
Forum: General Discussion and Questions
Topic: Valgrind Results
Replies: 7
Views: 235

Re: Valgrind Results

For reference, this is the relevant part of the output for debug builds of v1.15, I just excluded some of the traces which occur multiple times: ==3803== Conditional jump or move depends on uninitialised value(s) ==3803== at 0x120435: gc_collect_root (gc.c:347) ==3803== by 0x192126: gc_helper_collec...
by stijn
Mon Apr 19, 2021 7:08 pm
Forum: General Discussion and Questions
Topic: Help needed for beginner - memory alloc and classes
Replies: 7
Views: 130

Re: Help needed for beginner - memory alloc and classes

ikkeT wrote:
Mon Apr 19, 2021 6:41 pm
Or should such import be in __init__ function of the class?
Yes, or in any other function. I honestly don't know what the effect is of putting it at class level, just that it doesn't import the names into an available scope..
by stijn
Mon Apr 19, 2021 6:33 pm
Forum: General Discussion and Questions
Topic: Help needed for beginner - memory alloc and classes
Replies: 7
Views: 130

Re: Help needed for beginner - memory alloc and classes

ikkeT wrote:
Mon Apr 19, 2021 6:15 pm
Is it so that one can't do the import from within the class?
No that's not a problem (assuming you mean 'in a function in a class' or so, not sure what importing at class level does but if it's wrong it'll be a syntax error, it won't just silently mess up)
by stijn
Mon Apr 19, 2021 6:29 pm
Forum: General Discussion and Questions
Topic: Valgrind Results
Replies: 7
Views: 235

Re: Valgrind Results

Sorry forgot about this thread. The output now doesn't have file/line numbers in the stacktraces anymore so it's impossible to see what the errors are about. Compile again in debug mode (make DEBUG=1). Debug mode will also fix the reported memory leak: for some reason the release builds of the unix ...
by stijn
Mon Apr 19, 2021 6:06 pm
Forum: General Discussion and Questions
Topic: Share variable between C and Micropython
Replies: 1
Views: 58

Re: Share variable between C and Micropython

Bit hard to answer without more concrete information; essentially in C every MicroPython variable is going to be of type mp_obj_t. But how to best get to them depends on what/how you want to use this. I.e. are you implementing a custom type in C which getts exposed via a module? Then look at example...
by stijn
Mon Apr 19, 2021 6:01 pm
Forum: General Discussion and Questions
Topic: Help needed for beginner - memory alloc and classes
Replies: 7
Views: 130

Re: Help needed for beginner - memory alloc and classes

Have you tried running it without the display part and just printing to the console or a text file? Could very well be the fonts etc just hit the memory limit of your device. Underscores aren't going to change much as far as memory usage go. What you can do to figure out which component uses most me...
by stijn
Mon Apr 19, 2021 6:00 am
Forum: General Discussion and Questions
Topic: Why mp_type_framebuf is declared as STATIC?
Replies: 3
Views: 104

Re: Why mp_type_framebuf is declared as STATIC?

By default anything which isn't part of the public API, i.e. doesn't get exposed and remains local to a source file, is declared static. This is cleaner, plus as fas as I'm aware it allows certain optimizations both with respect to performance and code size. You're not the first one with this questi...