You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@arrow.apache.org by "ava6969 (via GitHub)" <gi...@apache.org> on 2023/04/19 00:01:07 UTC

[GitHub] [arrow] ava6969 opened a new issue, #35226: Any Possible issue in creating std::span from buffer memory directly

ava6969 opened a new issue, #35226:
URL: https://github.com/apache/arrow/issues/35226

   ### Describe the usage question you have. Please include as many useful details as  possible.
   
   
   I recently have been accessing const raw data from ArrayData holding doubles. by doing the following
   
   auto ptr =    reinterpret_cast<const double*>(m_array->data()->buffers[1]->data()) + m_array->offset();
   std::span<double> view(ptr, m_array->length);
   
   i found when null values exist they are 0; which is fine for my application. but are they are any other thing i should be thinking of.
   
   
   ### Component(s)
   
   C++


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@arrow.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow] westonpace commented on issue #35226: Any Possible issue in creating std::span from buffer memory directly

Posted by "westonpace (via GitHub)" <gi...@apache.org>.
westonpace commented on issue #35226:
URL: https://github.com/apache/arrow/issues/35226#issuecomment-1516558160

   Null values are not guaranteed to be 0.  We use a separate bitmask validity vector to determine if an element is null or not.  If an element is null then it's value is undefined and could be anything.
   
   However, creating spans from buffers is fine.
   
   Those spans will not keep the buffer alive though.  So you need to avoid something like this:
   
   ```
   std::span GetMyData() {
     std::shared_ptr<Array> m_array = GetSomeArray();
     auto ptr = reinterpret_cast<const double*>(m_array->data()->buffers[1]->data()) + m_array->offset();
     std::span view(ptr, m_array->length);
     return view;
   }
   ```
   
   Also, that reinterpret cast is only valid if `m_array->data()->buffers[1]->data()` is 8-byte aligned.  This is true for any buffer allocated by Arrow-C++ and is supposed to be true for any buffer sent over IPC but it is not currently guaranteed for buffers received over Flight due to https://github.com/apache/arrow/issues/32276.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org