Questions tagged [memory-optimization]

75 questions
114
votes
9 answers

Reducing memory usage of .NET applications?

What are some tips to reduce the memory usage of .NET applications? Consider the following simple C# program. class Program { static void Main(string[] args) { Console.ReadLine(); } } Compiled in release mode for x64 and running…
Robert Fraser
  • 10,649
  • 8
  • 69
  • 93
16
votes
6 answers

Why is an integer always used as the controlling variable in a for loop?

There are often times when you know for a fact that your loop will never run more than x number of times where x can be represented by byte or a short, basically a datatype smaller than int. Why do we use int which takes up 32 bits (with most…
uriDium
  • 13,110
  • 20
  • 78
  • 138
14
votes
9 answers

Automated field re-ordering in C structs to avoid padding

I've spent a few minutes manually re-ordering fields in a struct in order to reduce padding effects[1], which feels like a few minutes too much. My gut feeling says that my time could probably be better spent writing up a Perl script or whatnot to…
Christoffer
  • 12,712
  • 7
  • 37
  • 53
11
votes
5 answers

Does unsetting array values during iterating save on memory?

This is a simple programming question, coming from my lack of knowledge of how PHP handles array copying and unsetting during a foreach loop. It's like this, I have an array that comes to me from an outside source formatted in a way I want to…
Soulriser
  • 419
  • 8
  • 16
10
votes
2 answers

Disk-based trie?

I'm trying to build a Trie but on a mobile phone which has very limited memory capacity. I figured that it is probably best that the whole structure be stored on disk, and only loaded as necessary since I can tolerate a few disk reads. But, after a…
chakrit
  • 61,017
  • 25
  • 133
  • 162
9
votes
6 answers

Memory efficient int-int dict in Python

I need a memory efficient int-int dict in Python that would support the following operations in O(log n) time: d[k] = v # replace if present v = d[k] # None or a negative number if not present I need to hold ~250M pairs, so it really has to be…
Bolo
  • 11,542
  • 7
  • 41
  • 60
8
votes
2 answers

Garbage collection and correct usage of pointers in Go

I come from a Python/Ruby/JavaScript background. I understand how pointers work, however, I'm not completely sure how to leverage them in the following situation. Let's pretend we have a fictitious web API that searches some image database and…
Vincent
  • 16,086
  • 18
  • 67
  • 73
6
votes
3 answers

What is the most memory efficient method of storing a large number of Strings in a map?

I want to store huge amounts of Strings in a Map, so that the MagicObjects can be accessed quickly. There are so many entries to this Map that memory is becoming a bottleneck. Assuming the MagicObjects can't be optimized, what…
Andreas Hartmann
  • 1,825
  • 4
  • 23
  • 36
6
votes
2 answers

C# struct memory optimization?

I had a job interview for probation(? I'm not sure if that's the word) and interviewer asked me to tell him what are the differences between structure and class. So I told him everything I knew and everything that I've read on msdn. And the guy said…
user3212350
  • 401
  • 1
  • 6
  • 18
6
votes
1 answer

Android Bitmap Pixels - write directly to file?

Background: The goal is to write a rather large (at least 2048 x 2048 pixels) image file with OpenGL rendered data. Today I first use glReadPixels in order to get the 32-bit (argb8888) pixel data into an int array. Then I copy the data into a new…
cmbellman
  • 303
  • 1
  • 10
5
votes
9 answers

Clean vector every loop iteration. What is the most memory efficient way?

I have a question about the std::vector. I have a very memory intensive algorithm where I forsee that predicting vector sizes and reserving enough memory for the vectors in advance will help me a lot with reducing memory usage. Which of the…
Nailer
  • 2,446
  • 1
  • 24
  • 34
5
votes
1 answer

shared memory optimization confusion

I have written an application in CUDA, which uses 1kb of shared memory in each block. Since there is only 16kb of shared memory in each SM, only 16 blocks can be accommodated overall, right? Though at a time only 8 can be scheduled, but now if some…
peeyush
  • 2,841
  • 3
  • 24
  • 43
5
votes
1 answer

C# optimize memory usage: How to free memory claimed by DataTable

Currently I'm optimizing memory-usage of an huge batch-program. The most memory is used by different DataTables. For examle, my DataTable dataTable is using approx 260MB. Like suggestet in the accepted answer of the thread "What is the memory…
Vortex852456
  • 721
  • 6
  • 23
5
votes
2 answers

Java: reducing memory consumption by 2D float (floats[][]) arrays

I have Java application, which intensively working with 2D float arrays (float[][] arrays), which actually holding images on black background. Both dimensions are equals (square) and are power of 2 (mostly are 256, 512, 1024), so areas close to…
Arsen
  • 153
  • 1
  • 12
4
votes
1 answer

Building a "sparse" lookup array minimizing memory footprint

let's say I want to build an array to perform a lookup to parse network protocols (like an ethertype). Since such an identifier is 2-byte long, I would end up with a 2^16 cells array if I use direct indexing: this is a real waste, because it is very…
ziu
  • 2,634
  • 2
  • 24
  • 39
1
2 3 4 5