Is there a way to specify that all member functions for a class or template are placed in a specific region? Specifying a section for each member function works, but makes maintenance of large classes more tedious. Ideally there should be a way to do this for all functions in a class or template. In the example below square() is placed in "sram2" but cube() is not. Thanks.
#pragma arm section code = "sram2" class foo { public: int __attribute__((section("sram2"))) square(int x) { return x * x; } int cube(int x) { return x * x * x; } }; #pragma arm section code
I'd probably be using a preprocessor macro.
How about at the object file level in the scatter file?
Thanks for your suggestions.
We do use a macro to simplify the __attribute__((section())) syntax when placing individual functions. Yet in some classes all member functions should be placed in the same region. A class level directive would be more desirable and simpler to maintain in the long run. Several classes and templates on this project implement over 60 member functions. Most functions are short so the implementation is in the class declaration.
Classes and templates are usually declared in header files. Scatter files allow you to assign object files to a section, but I don't believe there is a way to do so with specific classes or templates.
Wouldn't it be a good solution to put this class in a separate source file and have that object file tagged for a specific memory region?
If you want the code inlined, then you would normally not want it in a specific memory region, but in the currrent memory region used for the code that makes use of the inlined functionality.
Is there a way to specify that all member functions for a class or template are placed in a specific region?
For inline methods like in your example? Probably not. That would defeat the purpose of making them inline in the first place.
Inline methods don't have any particular location in memory to begin with, so no clear way of changing it. They are designed to appear in-line in every location they're called. That's their whole purpose.
Templated classes are less localizable than inlined ones by yet another wide margin.
If you want to control where a method implementation goes, you have to start by making the implementation out-of-line, and you should probably stop to even think about templates.
Thanks for your responses.
Implementing a member function within the class declaration does not necessarily make it inline. The ARM compiler appears to use a similar criteria for inlining member functions than for inlining standalone functions. Member functions can be placed in a specific section using __attribute__((section())), as is the case of foo::square() in the example. Specifying a section overrides the compiler's inlining criteria, e.g. the function will not be inlined if the caller is in a different section. It would be desirable to have a directive to place all members functions of a class in the same section, but apparently there is none.