You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2020/04/30 07:54:45 UTC

[GitHub] [arrow] vertexclique commented on a change in pull request #7061: ARROW-8629: [Rust] Eliminate indirection of zero sized allocations

vertexclique commented on a change in pull request #7061:
URL: https://github.com/apache/arrow/pull/7061#discussion_r417823393



##########
File path: rust/arrow/src/memory.rs
##########
@@ -20,34 +20,56 @@
 
 use std::alloc::Layout;
 use std::mem::align_of;
+use std::ptr::NonNull;
 
 pub const ALIGNMENT: usize = 64;
 
+///
+/// As you can see this is global and lives as long as the program lives.
+/// Be careful to not write anything to this pointer in any scenario.
+/// If you use allocation methods shown here you won't have any problems.
+const BYPASS_PTR: NonNull<u8> = unsafe { NonNull::new_unchecked(0xDEADBEEF as *mut u8) };
+
 pub fn allocate_aligned(size: usize) -> *mut u8 {
     unsafe {

Review comment:
       It is allowed in the language itself, though my personal opinion that this should be allowed neither in this codebase nor in general at the language level. By definition, it still goes to the OS and does the necessary kernel procedure.
   
   I didn't want to change this code piece at first, wanted to fix it at the caller site. But I've discovered that the forgetting this at the caller site or checking it creates yet another responsibility to a newcomer to code. So I've explicitly put it in the place of memory operations.




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

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