octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #49055] Wcast-align warnings on certain non-x8


From: CH
Subject: [Octave-bug-tracker] [bug #49055] Wcast-align warnings on certain non-x86 architectures
Date: Tue, 14 Mar 2017 17:56:40 -0400 (EDT)
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0

Follow-up Comment #2, bug #49055 (project octave):

I could think of two possible solutions for this issue which both involve
adapting the constructor of the octave_chunk_buffer:

1. Instead of allocating chars in the ctor, allocate a type with sufficient
alignment, i.e.: int64_t. Now, to have the same interface as before, a
reinterpret-cast to a char pointer has to be appended. This could entail an
aliasing issue.


tmp = new int64_t [size / sizeof(int64_t)];
dat = reinterpret_cast<char*>(tmp);


2. Directly allocating aligned memory using malloc; malloc automatically
aligns to "max_align_t". This also means instead of delete, free has to be
used in the destructor, but as the buffer is used for plain-old-data buffers
many of the new / delete benefits don't apply here anyway.


dat = std::malloc(size);


In both cases the warning will likely still show up due the specializing
(casting) of the buffer, yet the underlying memory would be guaranteed to be
aligned and the warning could be disabled.

It may be that depending on the implementation even for a char array aligned
memory is allocated by new, but as far as I know there is no guarantee in the
C++ Standard for alignment beyond the underlying type's size.


    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?49055>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]