Skip to content

Does anybody know how to convert a 1D array to a std::vector in the most optimal way? #773

Answered by angeloskath
cemlyn007 asked this question in Q&A
Discussion options

You must be logged in to vote

This is all about memory management. Since the vector manages its own memory then we can't just create a normal vector from an MLX array. If you just want to access the underlying elements though then it is as simple as

auto data = snake.data<int>();
for (int el = 0; el < snake.size(); el++) {
  // you can use elem_to_loc here or just el depending
  // on whether the data is contiguous or not
  //
  // do something with data[el]
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@cemlyn007
Comment options

Answer selected by cemlyn007
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants