Memory management is the act of managing computer memory by allocating portions of memory to programs as well as freeing memory so that it can be re-used.
4
votes
3answers
98 views
Are these memory-allocation wrapper functions kosher with all C compilers?
I have never been entirely comfortable using malloc() and free() directly. For one thing, 99% of the time that I would like to call malloc, I would prefer it to take two arguments like calloc and do ...
4
votes
2answers
147 views
Doubly Linked List Implementation C++, copy constructor and assignment operator
I have implemented a Doubly Linked List in C++. I have tested it and everything works as expected, but I am not sure if my copy constructor and assignment operator perform a Deep Copy. Can someone ...
3
votes
1answer
119 views
efficient smart pointer implementation in C++
So the idea behind this is mainly educational but I might even consider using it in reality if turns out to be good. Here's my first try at implementing smart_pointers
template<typename T>
...
2
votes
0answers
85 views
How to improve readability and memory footprint of this haskell script?
I have this small haskell script that I wrote some time ago to parse a set of financial CSV files to produce other CSV files. I've recently had a problem with large input files (around 300Mb) that I ...
2
votes
1answer
93 views
What is the most memory efficient way to load big arrays into PHP script?
I have a few big arrays stored in separate files that are included into PHP as and when they are required:
Array File:
<?php
$cty_arr["af"] = "Afghanistan";
$cty_arr["ax"] = "Åland Islands";
...
0
votes
0answers
15 views
D3D COM Object Pooling
I'm using the following pattern to pool D3D objects globally in my application. Is it a good idea (alternatives)? Is it thread-safe?
CComPtr<ID3D11Texture2D> create_texture(const ...
2
votes
0answers
192 views
d3.js realtime streamgraph memory problem
This page (full source & demo) displays a 2-channel horizontal d3.js Streamgraph that takes realtime mouse coordinates as data inputs for the graph.
However, it tends to gradually use up an ...
2
votes
1answer
59 views
Would this code cause memoryleaks?
My question is really simple. Does this code cause memoryleaks? If so, where/how/why?
HDC hDC, memDC = 0;
HBITMAP hBMP = 0;
HBITMAP hOldBMP = 0;
PAINTSTRUCT PS;
HBRUSH hb212121, hb141414, hb070707, ...
2
votes
2answers
202 views
A* shortest path algorithm optimization request
Good day to ya'll. I had this programming excericise of mine where I had to find the shortest path to an exit in an NxM -grid maze in under a second (both N and M would be anywhere between 3 and ...
3
votes
2answers
158 views
Will this kind of codes leak memory?
I am reading lot of articles regarding memory leaks. But i am not sure about below code. I usually do coding in this way. Can anyone tell me, will they leak memory?
I have doubts in following 3 ...
3
votes
2answers
270 views
malloc / free implementation
Purpose: Educational
Requirement: Given 64KB of memory, implement your own malloc and free
Method: First-Fit
struct Header
{
unsigned short next; //offset from _dBuffer in blocks of ...
0
votes
1answer
171 views
'How to debug Buffer Overrun Issues' erro. Can someone help me to fix my code? [closed]
I have this code that reads a file that already exists, but in the first "for" when it read the file and copies it to the "struct" when the index is 1, I get an error:
(A buffer Read overrun has ...
4
votes
2answers
206 views
Objective-C retain / release snippet
Here are some snippets I coded and I would like some feedback on my way of handling this:
I have a utility class, as a singleton, that provides me with a method named randomColor which returns a ...
4
votes
1answer
437 views
A blocking buffer manager to provide segments of a byte array
Since asynchronous operations (like Socket's Begin*-End* pairs and *Async methods) that use IOCP under the hood cause the byte array that you use as buffer to be pinned in the memory.
So if you ...
8
votes
4answers
463 views
Code works but memory usage is erratic
I have the following class which is a tool for retrieving MD5 hashes of files that are input into it. They can potentially be very large files and I require cancellation and progress report, hence why ...
2
votes
0answers
299 views
Where is the memory leak in this Delphi code? [closed]
I tried to ask this on Stack Overflow, but it got closed. Someone recommended I ask her, so ...
This is not a code review about style or maintainability - what you will see is less than 5% of my app, ...
3
votes
4answers
460 views
Improve C# code efficiency by leveraging dot net framework
I have written following code to find the minimum difference from a list of numbers.
Because I am using a loop once and LINQ again to find the minimum, the algorithm is O(N^2).
Can you please tell ...
2
votes
2answers
151 views
C++: Am I managing memory the right way?
Also, how would I go about putting my class in another file? Thanks!
#include <iostream>
using std::cout;
using std::endl;
class Array
{
int *arrayPointer;
public:
Array(int size);
...
2
votes
1answer
106 views
Initating in haskell, am I following a good way?
I'm a bit concerned about fucntion usage. There are so many diferent libraries/possible ways to do something that I'm not sure if the way I'm working at the moment is reasonable, or what I could ...
2
votes
2answers
197 views
C++ Vector memory management in Game of Life
I'm writing a simulator for Conway's Game of Life (http://en.wikipedia.org/wiki/Conway's_Game_of_Life) in C++ and I'm trying to make the code as idiomatic as possible.
The central object is a ...
3
votes
2answers
137 views
Can not clearing a local java.util.Vector cause a memory leak?
In the code below, does not clearing or setting the local variable completed to null create the potential for a memory leak?
private Vector<Element> elements;
private void update()
{
...
1
vote
2answers
140 views
Does this javascript code leak?
I've been coding in javascript for a bit over a year now but never paid much attention to memory leaks. (I know I'm an idiot)
I built my first long running AJAX heavy app and memory leaks are eating ...
0
votes
2answers
74 views
May be a memory leak somewhere or allocated memory not freed? [closed]
Here is the entire program, please help me, I've tried everything to find out what exactly is going with the memory. The problem is everything runs perfectly, but there are some extra characters ...
5
votes
6answers
320 views
Word count in C, learning more CS
After about 5 years of programming in dynamic languages such as Python and JS I am starting to feel I'm missing out of what happens under the hood. Languages such as these are really great because ...
2
votes
1answer
776 views
Backbone.js: Will this code get cleaned up by the garbage collector
I have been working on a Backbone.js application, and I am starting to think I am making a huge mistake.
I never fully understand garbage collecting, and how exactly some closures prevent it. I just ...
1
vote
0answers
85 views
Memory/Threads leaks, developing simple HTTP-server with WinSock2 [closed]
I begin to develop my tool, which works with net at the TCP level, which will present simple functions of web-server.
In testing my program I have got very bad mistakes:
Memory leaks
Creating ...
3
votes
1answer
400 views
Java: Find the smallest integer not in the list - Memory Efficiency
This is a fairly popular interview question that I conceptually understand but have never really attempted to implement. In other similar implementations of this in Java I have seen they typically ...
2
votes
1answer
818 views
For Large number of nodes Min Heap implementation Dijkstra's Algorithm throwing OutOfMemoryError Exception
I am implementing Dijkstra's Algorithm using Min Heap to speed up the code. For small number of nodes, the code is really running very fast. But for large number of nodes, my code is throwing ...
1
vote
1answer
138 views
Variable sized type allocation
I have a type that receives serial data over a pipe:
struct Packet : Base { // Base is POD, too
int foo;
char data[];
};
In the context, where I instantiate Packet, I already know how large ...
2
votes
1answer
235 views
Is this a valid usage of structure assignment in C?
Q: Please comment on the usage of structures and structure assignment operations in C
I am working on converting a MATLAB program to C using BLAS and LAPACK for linear algebra support. The MATLAB ...
2
votes
2answers
245 views
Read until EOF and realloc as needed
This is a function that reads until EOF and reallocs as it goes.
char *
read_to_end(int fd, int *bread)
{
ssize_t size, nread, rc;
char *buf, *tmp;
nread = 0;
size = MINLEN;
buf ...
3
votes
2answers
519 views
Tree Node class - deallocation in the destructor
Is my destructor correct does it properly deallocate the subtrees?
#ifndef HEADER_GUARD__TREE
#define HEADER_GUARD__TREE
#include <deque>
namespace Sandbox {
class Node {
public:
...
4
votes
1answer
387 views
Simple TCP client - memory issues
Does this snippet take too much memory? How can I let the connection opened with the function connectTo outside the forever loop?
import Control.Concurrent
import Network
import System.IO
import ...
1
vote
1answer
182 views
Am I using my data source array correctly?
When I want to make some quick tests for my UITableViewControllers, I usually create an NSArray that holds some dummy data. I would like to know if I'm doing anything wrong here:
First in ...
3
votes
1answer
325 views
Space to allocate before sprintf
I just finished chasing a Heisenbug that was entirely my fault. I'd like to avoid it happening again.
I have a function which formats a date to a certain preset format. Turns out I was not allocating ...
4
votes
2answers
286 views
Human (Imperfect) array (card) shuffle written in C
ok, so I've got this humanoid_shuffle I wrote in python... And I've been wanting to learn C so as an exercise I ported it to C, as this is my first venture into C and even the idea's of memory ...
5
votes
1answer
541 views
Memory issues with Find Strings Problem on InterviewStreet
Here is the code I wrote for the problem at http://www.interviewstreet.com/recruit/challenges/solve/view/4e1491425cf10/4efa210eb70ac where we need to to print the substring at a particular index from ...
4
votes
1answer
148 views
Is this a good algorithm for 2D collision, or will it allocate too much memory?
I have a Rectangle class, of which I have 5-6 vectors for each instance. The main vectors are the center and color of the object, while the secondary vectors represent more or less the north, south, ...
3
votes
1answer
136 views
Am I managing my memory correctly?
I read that if an object is made using the init it must be released, but if it's something like this elementFormula = [[NSMutableString stringWithString:@""] it is autoreleased. However, there are ...
3
votes
1answer
1k views
Super simple templated memory pool in C++
I have a small program where I have a background thread that plays sound, so it needs to run really fast, but it also needs to do a small amount of memory management. I didn't want to use normal new ...
7
votes
3answers
282 views
Reusing strings read from I/O
I am working on an application that reads lots of data from the network and puts it in a grid. I noticed that I could save some memory by reusing existing strings instead of always using the new ...
5
votes
1answer
433 views
Double-Ended Queue - Have I over-engineered it again?
I'm working on an implementation of the Double-Ended Queue as a Doubly-Linked List (for personal enrichment), and I was wondering if anyone minded taking a look at my Constructor/Destructor and Empty ...
4
votes
1answer
217 views
My program spikes from 100000K mem to 1000000K mem in a matter of minutes in my program in VB.net
I've created a program that uses System.Graphics to render a simple (small) 2D scene to the screen. The problem is, for some reason, it starts to quickly accumulate memory. In fact, it goes from ...
1
vote
2answers
235 views
NSAutoreleasePool with Json Data
Just need to know if I'm doing something wrong in this code. my app seem work fast now with this code. I just want to if i really understant that
- (void)receive
{
NSString *post2 = ...
5
votes
1answer
113 views
allocating Memory query? overloading the new operator, allocating more memory in the new operator for the adding more data
This may be a naive question but what are the dangers of the following code,(allocate more memory in the new operator for the info struct):
struct Info
{
Info():nLineNo(0){memset(cFile, 0, ...
3
votes
1answer
214 views
Does this I/O operation caused a memory leak
My colleague did some code Optimise work.
Code below is from a public method of a public class (NOT STATIC CLASS OR METHOD)
code before:
Bitmap btMap = new ...
1
vote
1answer
414 views
Memory Question
Can this part of a view controller subclass be checked for memory leaks. I am not that good at finding leaks. I need this class to be able to be loaded many time over without it crashing due to memory ...