malloc and stl container

Lange Norbert norbert.lange at andritz.com
Mon Jul 27 10:52:02 CEST 2020



> -----Original Message-----
> From: Xenomai <xenomai-bounces at xenomai.org> On Behalf Of Jan Holtz via
> Xenomai
> Sent: Montag, 20. Juli 2020 07:05
> To: xenomai at xenomai.org
> Subject: malloc and stl container
>
> NON-ANDRITZ SOURCE: BE CAUTIOUS WITH CONTENT, LINKS OR
> ATTACHMENTS.
>
>
>    Hello,
>    i am using xenomai 3.0 on a cobalt x64 smp system with the alchemy
>    skin.
>    As far i know dynamic memory allocation can cause a context switch,
>    which should be preventet.
>    If i am right,malloc should not cause a CSW anymore at this xenomai
>    version.

Don't see where you get this from. malloc might not cause a CSW every time,
but it has the potential to do so at *any* time.

>    If malloc don't cause a CSW,  in which case the alchemy heap management
>    services is suggested to use instead for dynamic memory allocation?
>    I like to use stl containers like vector, etc.
>    Is there a way to use this containers wthout adding values to
>    containers seems to cause a CSW.

A generic malloc will always have properties that are unwanted for
realtime. When do you need to resize vectors?
If you have a part of your system not running in RT you can resize your vectors there,
or you pre-allocate them to be big enough so they won't ever call malloc.

>    Can it work/wrapped with heap management services ?

The STL? Sure, you can use your own allocators (google: pool allocator), or something like boost::static_vector.
You still need to make sure you don’t cause allocations when in RT.

Norbert

>    Hope you can help me to understand.
>    Regards Jan
________________________________

This message and any attachments are solely for the use of the intended recipients. They may contain privileged and/or confidential information or other information protected from disclosure. If you are not an intended recipient, you are hereby notified that you received this email in error and that any review, dissemination, distribution or copying of this email and any attachment is strictly prohibited. If you have received this email in error, please contact the sender and delete the message and any attachment from your system.

ANDRITZ HYDRO GmbH


Rechtsform/ Legal form: Gesellschaft mit beschränkter Haftung / Corporation

Firmensitz/ Registered seat: Wien

Firmenbuchgericht/ Court of registry: Handelsgericht Wien

Firmenbuchnummer/ Company registration: FN 61833 g

DVR: 0605077

UID-Nr.: ATU14756806


Thank You
________________________________


More information about the Xenomai mailing list