Questions tagged [memory-efficient]

Use this tag for questions related to memory efficient code/applications/etc. .

Usually one would like to be , especially when dealing with bigdata, where the size of the data is so big, that memory usage can be a problem. At these applications, begin memory efficient or not, can determine dramatically whether your application will be successful or not.

Another example is in , when one would like to use a bit for a flag, instead of a hole integer, to save some space.

414 questions
332
votes
14 answers

What are the benefits to marking a field as `readonly` in C#?

What are the benefits of having a member variable declared as read only? Is it just protecting against someone changing its value during the lifecycle of the class or does using this keyword result in any speed or efficiency improvements?
leora
  • 163,579
  • 332
  • 834
  • 1,328
55
votes
2 answers

Is there a way to paste together the elements of a vector in R without using a loop?

Say there's a vector x: x <- c("a", " ", "b") and I want to quickly turn this into a single string "a b". Is there a way to do this without a loop? I know with a loop I could do this: y <- "" for (i in 1:3){ paste(y, x[i], sep = "") } > y [1]…
Max
  • 705
  • 1
  • 5
  • 9
44
votes
5 answers

What is a Memory-Efficient Doubly Linked List in C?

I had come across the term "Memory-Efficient Doubly Linked List" while reading a book on C Data structures. It just had one line saying that a memory-efficient doubly linked list uses less memory than a normal doubly linked list, but does the same…
23
votes
4 answers

Find duplicate in array with a memory efficient approach

A is an array of integers. All the values are between 0 to A.Length-1 it means 0 <= A[i] <= A.Length-1 I am supposed to find repeating elements; and if there are several repeating elements, then choose the one that has lower index for the repeated…
23
votes
4 answers

Most memory-efficient way to compute abs()**2 of complex numpy ndarray

I'm looking for the most memory-efficient way to compute the absolute squared value of a complex numpy ndarray arr = np.empty((250000, 150), dtype='complex128') # common size I haven't found a ufunc that would do exactly np.abs()**2. As an array…
15
votes
4 answers

How to split an array into chunks with jq?

I have a very large JSON file containing an array. Is it possible to use jq to split this array into several smaller arrays of a fixed size? Suppose my input was this: [1,2,3,4,5,6,7,8,9,10], and I wanted to split it into 3 element long chunks. The…
Echo Nolan
  • 919
  • 12
  • 20
15
votes
2 answers

How to efficiently store small byte arrays in Java?

By small byte arrays I mean arrays of bytes with length from 10 up to 30. By store I mean storing them in the RAM, not serializing and persisting to the filesystem. System macOS 10.12.6, Oracle jdk1.8.0_141 64bit, JVM args -Xmx1g Example: Expected…
kisileno
  • 757
  • 8
  • 22
11
votes
6 answers

what's more efficient? to empty an object or create a new one?

how expensive is 'new'? I mean, should I aim at reusing the same object or if the object is 'out of scope' it's the same as emptying it? example, say a method creates a list: List list = new ArrayList(); at the end of the method…
adhg
  • 8,947
  • 8
  • 51
  • 88
11
votes
1 answer

Split a 3D numpy array into 3D blocks

I would like to split a 3D numpy array into 3D blocks in a 'pythonic' way. I am working with image sequences that are somewhat large arrays (1000X1200X1600), so I need to split them into pieces to do my processing. I have written functions to do…
mdriscoll
  • 163
  • 2
  • 6
11
votes
4 answers

Does Slicing `a` (e.g. `a[1:] == a[:-1]`) create copies of the `a`?

A friend of mine showed me the following Python code: a[1:] == a[:-1] Which returns True iff all the items in a are identical. I argued the code is hard to understand from first sight, and moreover - it is inefficient in memory usage, because two…
Adam Matan
  • 107,447
  • 124
  • 346
  • 512
11
votes
2 answers

Fast and memory efficient ASCII string class for .NET

This might have been asked before, but I can't find any such posts. Is there a class to work with ASCII Strings? The benefits are numerous: Comparison should be faster since its just byte-for-byte (instead of UTF-8 with variable encoding) Memory…
Robin Rodricks
  • 99,791
  • 133
  • 372
  • 575
9
votes
6 answers

Pthreads - High memory usage

I am programming something in C that creates a lot of Pthreads in Linux on a 256Mb system. I usually have +200Mb free. When I run the program with a low amount of threads it works, but once I make it create around 100 threads it gives errors because…
NeDark
  • 1,203
  • 4
  • 22
  • 33
9
votes
2 answers

Object orientation, data orientation, cache pollution and cache obviousness

In a regular object oriented practice it is not that rare objects have multiple unrelated member properties. And when objects are being processed, it is not rare that it is done in different passes, which aim for different parts of their…
dtech
  • 44,350
  • 16
  • 93
  • 165
7
votes
2 answers

Is the wide or long format data more efficient?

I am just curious whether it is more efficient to store data in long or wide format regardless of the interpretative? I have used object.size() to determine the size in the memory but they do not differ significantly (the long being slightly more…
MKao
  • 241
  • 2
  • 10
7
votes
1 answer

Most efficient way to get an integer type id in a family of common base types

The problem: I have a family of objects with a common base, and I need to be able to identify the specific concrete type via an integer value. There are two obvious approaches to do that, however both come with unacceptable overheads in terms of…
dtech
  • 44,350
  • 16
  • 93
  • 165
1
2 3
27 28