Sharing Structs Between Objects


#1

Is it possible to do the following?

In Object A

  • define a data struct in Local Data
  • define and populate an instance of struct with data (preferably in SDRAM) in Init Code

In Object B

  • Access data stored in struct in Object A using object-name-reference stored in ObjRef attribute and standard struct-access .syntax

I know this is an obscure thing to want to do, but I have a good reason (I think).

a|x


#2

It does seem to be possible, but not to put the struct into SDRAM. I guess that's only for unstructured arrays.

struct_send_test.axp (2.1 KB)

I'd like to know if this would work properly with polyphonic patches, though, or if it could be tweaked to store the struct in SDRAM.

a|x


#3

yes its possible , but your syntax is incorrect.

try

static  const _myStructDef _myStruct __attribute__ ((section (".sdram"))) = {.myBool = true, .myInt = 345} ;

your mixing up declaration and initialisation, so this is probably worth you reading up about.

also _myStructDef is not a good naming convention (in C) as its a type name, its a good practice to use different naming styles for types and instances, otherwise things get confusing fast :wink: (if you want other programmers to look at it)

your next issue, is about const, you have to initialise constants, you cannot just assign them (so your pointer assignment will fail)... again, lots of stuff on the net and in C/C++ books about this.

EDIT: http://stackoverflow.com is a great resource for searching for syntax errors and fixing, actually just a great programming resource full stop. every programming question ever asked, has been answered there.... ok, slight exaggeration, but you'll be amazed at its coverage :slight_smile:


#4

Thanks very much for the tips.

I must admit, I have been confused about declaration and initialisation for a while now. I really should have read up on it earlier. I'll probably have to go through all the objects I've made and change things to make more sense (though they do appear all to be working, somehow).

Re. naming conventions:
I know what you mean. I did try adding the underscore to the type name, but then I stupidly added it also to the name of the struct, to make it look different to the pointer that points to it, as I've seen this done in the factory file-read object.

Is there a 'standard' or common convention for type definition naming? ALL_CAPS for type definition names, perhaps?

Re. stackoverflow:
I know it well. I've spend a LOT of time on there over the years, believe me...
I'm not a noob programmer, just new to C (or at least building on a very limited knowledge of it, from many years ago, which more-or-less amount to the same thing).
Having said that, I'm 100% self-taught, so don't have a strong grasp on some of the basics, to my shame.

a|x


#5

I believe the problem is not the struct in sdram, but the initializer, assigning initial data for something in sdram.

A static variable means its contents will be shared in a polyphonic context. The static keyword is required to be able to specify alternate memory segments, required for sdram and DMA. To use sdram without sharing data across all voices, a static array can be used with an element per voice. The table and delay objects use this approach.


#6

there are lots of naming conventions :slight_smile:
I guess today, many use the google style guide, so thats as good as any.

one tip, look at the xpatch.cpp, and find the instance of the object you have created, it can be important at times to see what the generated C++ class looks like, and how your code is inserted.
also if you turn on expert mode (axoloti prefs), you can even edit the xpatch.cpp directly and compile it, can be useful for trying things out.
if you do look at the xpatch.cpp, Id recommend a code formatter , like astyle, to reformat it first, it makes it much easier to read.


#7

This does seem to work though, with the constant declared and initialised (isnt that what the {true, 345} does?) in the Init Code section of the sender object.

a|x

struct_send_test.axp (2.0 KB)


#8

Is it possible for one object to allocate multiple items in SDRAM?

I'm trying to allocate an array and a struct (as above) as two separate chunks of data in SDRAM.

If I make the struct (and the pointer pointing to it) constant, as above, I get an error:

/Users/alx/Documents/axoloti/build/xpatch.cpp:815:16: error: vsm_rom_data_sdram causes a section type conflict with lpc_tables_sdram
static uint8_t vsm_rom_data_sdram[1][LENGTH] __attribute__ ((section (".sdram")));
^
/Users/alx/Documents/axoloti/build/xpatch.cpp:1014:28: note: 'lpc_tables_sdram' was declared here
static const Tms5100Coeffs lpc_tables_sdram[1] __attribute__ ((section (".sdram"))) = T0280B_0281A_coeff
^

If I make the struct in SDRAM non-constant, it doesn't generate an error, but the values retrieved by the receiver objects are garbage.

It works fine if I allocate the struct in SRAM.

a|x