This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Placing C++ member functions at specific region

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

Parents
  • 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.

Reply
  • 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.

Children
  • 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.