marin-ma commented on code in PR #7861:
URL: https://github.com/apache/incubator-gluten/pull/7861#discussion_r1845832814


##########
cpp/core/shuffle/Utils.cc:
##########
@@ -212,6 +215,96 @@ arrow::Result<std::shared_ptr<arrow::RecordBatch>> 
makeUncompressedRecordBatch(
   }
   return arrow::RecordBatch::Make(writeSchema, 1, {arrays});
 }
+
+arrow::Result<std::shared_ptr<MmapFileStream>> MmapFileStream::open(const 
std::string& path) {
+  ARROW_ASSIGN_OR_RAISE(auto fileName, 
arrow::internal::PlatformFilename::FromString(path));
+
+  ARROW_ASSIGN_OR_RAISE(auto fd, arrow::internal::FileOpenReadable(fileName));
+  ARROW_ASSIGN_OR_RAISE(auto size, arrow::internal::FileGetSize(fd.fd()));
+
+  void* result = mmap(nullptr, size, PROT_READ, MAP_PRIVATE, fd.fd(), 0);
+  if (result == MAP_FAILED) {
+    return arrow::Status::IOError("Memory mapping file failed: ", 
::arrow::internal::ErrnoMessage(errno));
+  }
+
+  auto fstream = std::shared_ptr<MmapFileStream>(new MmapFileStream());
+  fstream->fd_ = std::move(fd);
+  fstream->data_ = static_cast<uint8_t*>(result);
+  fstream->size_ = size;

Review Comment:
   Can we use std::make_shared and set the argument through ctor?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to