Questions tagged [contiguous]

145 questions
204
votes
8 answers

What does .contiguous() do in PyTorch?

What does x.contiguous() do for a tensor x?
MBT
  • 21,733
  • 19
  • 84
  • 102
52
votes
5 answers

What does std::vector look like in memory?

I read that std::vector should be contiguous. My understanding is, that its elements should be stored together, not spread out across the memory. I have simply accepted the fact and used this knowledge when for example using its data() method to get…
egst
  • 1,605
  • 3
  • 18
  • 25
24
votes
1 answer

Split regex to extract Strings of contiguous characters

Is there a regex that would work with String.split() to break a String into contiguous characters - ie split where the next character is different to the previous character? Here's the test case: String regex = "your answer here"; String[] parts =…
Bohemian
  • 412,405
  • 93
  • 575
  • 722
20
votes
1 answer

Why does std::vector have no .data()?

The specialisation of std::vector, as specified in C++11 23.3.7/1, doesn't declare a data() member (e.g. mentioned here and here). The question is: Why does a std::vector have no .data()? This is the very same question as why is a vector…
schorsch312
  • 5,553
  • 5
  • 28
  • 57
18
votes
2 answers

Is the memory in std::array contiguous?

Is the memory in std::array contiguous? Is the following valid/good practice? std::array arr = //initialize value type1 * ptr = &arr[0]; Could I then pass ptr to functions expecting a c-style array?
Riley
  • 982
  • 1
  • 7
  • 19
15
votes
2 answers

Check if numpy array is contiguous?

How can I find out if a n-dimensional numpy array Arr is contiguous in C-style or Fortran-style?
Ethunxxx
  • 1,229
  • 4
  • 16
  • 34
11
votes
3 answers

In C++20, how do I write a contiguous iterator?

C++20 has explicit library support for std::contiguous_iterator_tag. Some STL algorithms (e.g. std::copy) can perform much better on contiguous iterators. However, I'm unclear on exactly how the programmer is supposed to get access to this new…
Quuxplusone
  • 23,928
  • 8
  • 94
  • 159
10
votes
3 answers

Mark non-contiguous date ranges

Background (Input) The Global Historical Climatology Network has flagged invalid or erroneous data in its collection of weather measurements. After removing these elements, there are swaths of data that no longer have contiguously dated sections.…
Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315
9
votes
6 answers

std::vector and contiguous memory of multidimensional arrays

I know that the standard does not force std::vector to allocate contiguous memory blocks, but all implementations obey this nevertheless. Suppose I wish to create a vector of a multidimensional, static array. Consider 2 dimensions for simplicity,…
user787267
  • 2,550
  • 1
  • 23
  • 32
9
votes
1 answer

std::vector: contiguous data and copy/move

I have two questions for the following code: 1) Will the elements of faces be contiguous? 2) Does std::vector copy or move Face f when inserting it? #include int main() { struct Face {}; std::vector faces; for (int…
Shibli
  • 5,879
  • 13
  • 62
  • 126
9
votes
1 answer

When is worst fit in memory allocation useful

I'm reading operating system concepts essisentals 8th edition. When the author goes over contiguous memory allocation and worst fit the author states "Allocate the largest hole. Again, we must search the entire list unless it is sorted by size. This…
Austin Davis
  • 3,516
  • 10
  • 27
  • 47
8
votes
1 answer

Why is there no std::data() overload for std::valarray?

C++11 introduced std::begin(std::valarray&) as well as std::end(std::valarray&). C++17 introduced std::data() which works with std::vector, std::array, C-style arrays, etc. But why wasn't an overloaded std::data() introduced for…
Emile Cormier
  • 28,391
  • 15
  • 94
  • 122
8
votes
1 answer

How to allocate large contiguous, memory regions in Linux

Yes, I will ultimately be using this for DMA but lets leave coherency aside for the moment. I have 64 bit BAR registers, therefore, AFAIK, all of RAM (e.g. higher than 4G) is available for DMA. I am looking for about 64MB of contiguous RAM. Yes,…
tallen
  • 677
  • 6
  • 17
7
votes
6 answers

Why storing a tree as a contiguous chunk of memory?

I just discovered that there are some tree based data structure that, when looking for high performance, are often times stored as a contiguous chunk of memory, this is especially popular when using the so called "policy based data structure" . The…
user2485710
  • 9,451
  • 13
  • 58
  • 102
6
votes
2 answers

Managing a Contiguous Chunk of Memory without Malloc/New or Free/Delete

How would one go about creating a custom MemoryManager to manage a given, contiguous chunk of memory without the aid of other memory managers (such as Malloc/New) in C++? Here's some more context: MemManager::MemManager(void* memory, unsigned…
user4148144
1
2 3
9 10