Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

Questions tagged [memory-optimization]

Memory Optimization is a subset of Optimization: it is the goal of reducing the memory consumption (the amount of memory used during compile or run time) of your program or of a specific algorithm

Filter by
Sorted by
Tagged with
3 votes
2 answers
204 views

Calculating Pi with Android

I'm kind of new to Java but I am writing an Android app. Right now I'm working on an async task to calculate Pi but when I run it the memory usage increases alarmingly (+5MB per second). This one ...
user avatar
  • 131
2 votes
2 answers
1k views

Project Euler #15 in Python

I've wrote the code for Project Euler #15 and it runs amazingly fast. I know I can write it using binomials but I wanted to calculate by brute force as if I do not know Binomials. But I think it must ...
user avatar
2 votes
1 answer
502 views

Basic memory pool, alignment, thread safety

Mainly for practicing purposes, I'm trying to implement a simple, yet efficient memory pool. It's basically a linked list that is able to grow, with fixed sized members. Each node has a flag if it's ...
user avatar
  • 53
1 vote
0 answers
418 views

Scraping websites and saving to MySQL

I have the following piece of code which scrapes websites and saves some information back to MySQL. At the moment is consuming all the memory on my machine every time it runs. I've refactored the ...
user avatar
  • 481
2 votes
2 answers
333 views

Creating monthly files from an annual file

I am interested in learning a more succinct (or better performing) way of writing the following working code. I just figured it out but it is pretty messy. This program takes a file full of daily ...
user avatar
  • 33
0 votes
2 answers
181 views

Calculating shortest possible route between two given nodes

I recently came across this problem: Heroes in Indian movies are capable of superhuman feats. For example, they can jump between buildings, jump onto and from running trains, catch bullets with ...
user avatar
  • 389
1 vote
2 answers
2k views

Finding the longest palindrome from the given string

Recently I came across this problem which instructs me to find the longest substring which is a palindrome: As we all know, a palindrome is a word that equals its reverse. Here are some examples ...
user avatar
  • 389
3 votes
3 answers
452 views

Calculating number of unharmed leaves

I recently came across this problem that asks you to print the number of leaves not eaten by the caterpillars: As we all know caterpillars love to eat leaves. Usually, a caterpillar sits on leaf, ...
user avatar
  • 389
4 votes
1 answer
3k views

Find files with content matching regex

Today I wanted to find a program that I wrote a while ago. I knew that it contained a certain regex, but I couldn't for the life of me remember the file name I saved it under. I knew I could use ...
user avatar
  • 41.6k
1 vote
1 answer
2k views

Brute-force password cracker

I am trying to write a program to find a zip file's password. I know the password consists of only lower-case letters and it's length does not exceed 6 characters. I wanted to check the passwords of ...
user avatar
  • 13
8 votes
3 answers
168 views

How to decrease memory usage in codeeval Road Trip challenge

I'm solving easy CodeEval challenges in Python 2.7. Usually my solutions use around 256 bytes of memory according to CodeEval. With Road Trip however while time used is still low (30-40ms), memory is >...
user avatar
  • 83
2 votes
1 answer
137 views

Profit sensitivity analysis in base R

Using base R, I've conducted a simple profit sensitivity analysis, i.e. measuring the impact on profit if there is a change in price, variable cost per sale, unit sales or fixed costs assuming that ...
user avatar
3 votes
0 answers
52 views

LinkedList of Nodes at each level - optimalization

That's already known problem: to return an array of linked lists that contain values of elements at each level. Eg for tree with depth n there should be n linked lists. I wrote the solution: ...
user avatar
  • 131
3 votes
1 answer
130 views

Writing a byte array image to disk with an automatically generated filename

I have the following code that that writes large images to disk. My application server is running out of memory and I'm wondering if I could somehow optimize the following: ...
user avatar
2 votes
2 answers
81 views

Find the best path amongst N random points

For an application with a graphical canvas, I want to generate N points. But then I want to link those points, and I want to find the best path through those points. I wanted to use a dynamic ...
user avatar
4 votes
1 answer
186 views

Memory efficient Log Parser

I wrote this together for a test I'm doing that parses the Heroku access log. What I'm mainly interested is if this code follow common best practices and if there are any improvements I can make in ...
user avatar
1 vote
1 answer
4k views

Multiple emails and attachments, reusing memory stream

I am generating a pdf form based on user input from an MVC website form. The pdf is genrated using the Foxit .NET SDK, then attached to three separate emails, generated using Postal. It has been ...
user avatar
  • 173
4 votes
2 answers
952 views

Memoized Collatz sequence

Here is one of my programs that utilized memoization and array to improve performance and memory usage. The performance seems satisfactory but the memory usage is ridiculous and I can't figure out ...
user avatar
  • 143
7 votes
3 answers
9k views

Rotation of elements in an array

We had to write a program that would perform rotation of elements in an array. The array size was entered by user, so it had to be in a sense, dynamic. Rotation or Circular Shifting Initial Array: <...
user avatar
  • 359
4 votes
2 answers
882 views

Memory Management Code

For a project I had to do a memory management problem without creating any custom classes or templates using the provided pool array and ...
user avatar
4 votes
2 answers
1k views

Binary file validity in C++/C++11: checking a binary header

I have some code for checking a binary header to see if a binary file is meant to be read by a certain program, and I could use some extra eyes to review it. Assume the following ...
user avatar
  • 43
4 votes
1 answer
331 views

Construct binary tree from inorder and postorder traversal

The problem is taken from here. The tree is guaranteed not to have duplicate elements. My questions is, instead of creating new arrays leftInOrder, ...
user avatar
3 votes
2 answers
822 views

Find two numbers that add up to a given total, from a formatted string

The full challenge from codeeval.com can be viewed here. Input Your program should accept as its first argument a filename. This file will contain a comma separated list of sorted numbers ...
user avatar
  • 133
4 votes
2 answers
220 views

Computing the double Integral using MonteCarlo techniques using Julia

I decided to try and learn Julia for doing scientific computing, and I decided to tackle the problem of finding $$ \int_{D_{\frac{1}{4}}} x^4 + y^2 dA $$ where \$ D_{\frac{1}{4}} \$ is the part of ...
user avatar
-1 votes
1 answer
260 views

Simplest linked list in C++?

My context was basically to get my linked list implementation in C++ reviewed, since I wrote it from scratch and wanted to make it as simple as possible and learn from suggestions I get. I am trying ...
user avatar
  • 121
6 votes
2 answers
288 views

Extending Sieve of Eratosthenes beyond a billion - follow-up

Follow up form Extending Sieve of Eratosthenes beyond a billion Taking suggestions from the comments on the previous post: Updated Code: This takes about 22 seconds for MAX as \$10^9\$ to reach "...
user avatar
  • 801
12 votes
1 answer
311 views

Where it all begins: Khronos

This is the main.c file for Khronos, a personal project of mine. This is basically where the whole program is setup, run and then quit. I'll post the short ...
user avatar
  • 21.6k
31 votes
4 answers
3k views

Extending Sieve of Eratosthenes beyond a billion

For MAX value of 1000000000 (\$10^9\$), it takes about 45 seconds to reach the line where it prints "done". How can I speed this ...
user avatar
  • 801
20 votes
1 answer
3k views

Bruteforce MD5 Password cracker

I just started learning Go, and I wanted to created a project to learn more about concurrency in go. I heard about Go's lightweight threads, so I wanted to give them a try. This program uses ...
user avatar
9 votes
2 answers
2k views

Frequency count of single words and word pairs over 20 million tweets

My application needs to read 20-million-line text files and count the word frequencies for one and two words. For example: A B A B SSS G D A One word Frequency A: 3 B: 2 SSS: 1 G: 1 Two Word ...
user avatar
3 votes
1 answer
218 views

Tic Tac Toe with Minimax (memory management optimization)

I've made a Tic Tac Toe game with minimax in Javascript. It works but I have to use location.reload(true); to automatically reload the page every time user starts a ...
user avatar
  • 145
7 votes
3 answers
569 views

Type-agnostic BubbleSort in C

I'm trying out different sorting algorithms for learning purposes, here I'm doing a "type-agnostic" bubbleaort. I modeled the function signature after the standard library's ...
user avatar
  • 436
5 votes
1 answer
1k views

Updating number of votes with a "Like" button

I have a "Like" button in my iOS app that updates the votes every time it's tapped. Just like Facebook, Instagram, ProductHunt, etc. I have a custom cell where that ...
user avatar
  • 205
4 votes
1 answer
615 views

Conway's Game of Life

Inspired by this post, I decided to try to implement my own Conway's Game of Life. I started with a non-warping board: ...
user avatar
  • 9,414
2 votes
1 answer
66 views

Compare a sequence with the reference frequency of hexamers

I have written this function (and others similar to that one) But I am not sure I am using references on their full power. My currently concerns is if I make a huge use of memory. The subroutine ...
user avatar
  • 283
4 votes
1 answer
91 views

Binary/yijing clock in Processing with excessive resource consumption

I've been learning Processing for the last week or two, and I've made a couple of little 'desktop toy' type apps like this one that I'm quite pleased with. However, it just occurred to me today to ...
user avatar
  • 295
2 votes
0 answers
570 views

"Partial solution" on Code Eval for Clojure FizzBuzz

I'm just getting started on the site CodeEval, and I submitted my first solution today. What I don't understand is why it's marking my (working) answer as only a "partial solution". The site doesn't ...
user avatar
  • 33
2 votes
1 answer
1k views

Extract data from large JSON and find frequency of contiguous sub lists

I have been writing some code (see component parts here and here) that: Takes a very large JSON (15GB gzipped, ~10million records) Extracts the relevant parts of the JSON into a list of lists Creates ...
user avatar
  • 85
4 votes
1 answer
2k views

Pulling data from API, Allowed memory exhausted

I'm working on a project where I pull data (JSON) from an API. I would like to manipulate this data and store this as useful information in my DB (MySQL). My code is working if I would like to make, ...
user avatar
  • 141
10 votes
2 answers
1k views

Unique value finder

For our first assignment in our algorithm class we are suppose to solve several different questions using information from a 2D array. We are also suppose to optimize our code to get more marks on our ...
user avatar
  • 101
3 votes
3 answers
183 views

Storing and processing large arrays to compute dot products

Problem Statement (from HackerRank) We have two arrays \$a\$ and \$b\$ of length \$N\$, initially all values equals to zero. We have \$Q\$ operations. Let's define three types of operations on ...
user avatar
7 votes
1 answer
741 views

Monitoring the recursive growth of a zombie rabbit population

Breeding like rabbits Write a function answer(str_S) which, given the base-10 string representation of an integer \$S\$, returns the largest n such that \$R(...
user avatar
  • 613
6 votes
1 answer
339 views

Sieve of Eratosthenes for prime generation

I was originally going to write this intro as just being the bare-bones "here's my problem, here are some ideas, what do you recommend" format (which I am still going to follow, mind you), but I've ...
user avatar
  • 809
8 votes
2 answers
275 views

Summation of primes for large inputs

I'm doing a problem from Project Euler to find the sum of all primes under two million. My code manages to get a pretty good result for small inputs, but when trying inputs like million or two it ...
user avatar
  • 223
5 votes
1 answer
447 views

CodeEval solutions to find trailing strings

This is a problem in CodeEval, moderate level. The problem is very easy for this level. But I am not able to get more than 60 points for any solution I submit. (Moderate levels highest score is 65 and ...
user avatar
3 votes
3 answers
3k views

Custom ArrayList class

Please review my custom ArrayList class I constructed from scratch and add any suggestions or constructive criticisms. The point of this template class is give the ...
user avatar
4 votes
2 answers
1k views

Memory efficient A* (AStar) Algorithm

I am writing a solved for 15 puzzle game which will find the solution path to any NxN board. For easier boards the algorithm works great solving almost any 3x3 boards, most 4x4 boards, but when I go ...
user avatar
  • 43
4 votes
2 answers
1k views

Object-oriented JavaScript and Google Maps objects memory management

I have to draw various instances of HeatMaps, Winds and Polylines. Each layer will have one <...
user avatar
3 votes
3 answers
1k views

Web crawler uses lots of memory

I am developing a web crawler application. When I run the program for more than 3 hours, the program runs out of memory. I should run the program for more that 2-3 days non-stop to get the results I ...
user avatar
6 votes
1 answer
228 views

Pool allocator for a scripting language parser

At the moment I'm writing a parser and interpreter for a custom scripting language, to learn more about the basic concepts involved and to get more familiar with tools like ...
user avatar
  • 17k