memory-allocation

Creating c++ object on the stack, trying hard not to ever allocate.

Suppose I have a class class A { public: A(int i); ~A(); private: B b; // Want <- this guy to be constructed with i in A's constructor! }; I want b to be constructed in the constructor with particular parameters that aren't known until A is constructed. If I were to do the following in A's constr...

What is causing the OS to become slow after running a memory intensive Java application?

I am currently running a small java class for scientific calculations on graphs (which internally creates lots of huge collections) from within Eclipse on MacOSX Snow Leopard. I have a Macbook with 2GB of RAM and to successfully run the app without OutOfMemory Error I need to run it from eclipse with -Xmx1200m (I know this is very much)....

How to design extremely efficient function

I am designing a function (Java method) which will be executed 40-80 times per second on a mobile device. I want to avoid producing a ton of dead variables which get collected by GC, as the function runs (possibly throughout the life of the app). In C I might use volatile for example, to prevent the memory allocation of my variables ...

Bad memory allocation C++ for a vector

I get std_bad_alloc error in the following code. It seems the problems is when I add the matrix to the vector, the program crashes when I get to that line in the debugger. The problem is that only the first two matrices are read from the file, the other two aren't because the program crashes with the above error. ...

Custom memory allocator/manager in C ? which approach?

I looking for some (custom) memory managers/allocator written in c and went through some articles, - Some Links : IBM - Inside memory management Valgrind - How to Shadow Every Byte of Memory Used by a Program Stack Overflow Question - Write your own memory manager ned Productions - nedmalloc Homepage Two-Level Segregate Fit (TLSF) - W...

Using Electric Fence (libefence) just for a shared library

In order to diagnose a tricky memory corruption bug (memory is getting randomly overwritten) I thought about utilizing Electric Fence + some custom mprotect calls to ensure that the corrupted data structures are only writable when I want them to be written to (and I immediately get a SIGSEGV when they are attempted to be written to). Un...

C# Overhead of evaluating 13 bits instead of native 16 bits

I'm compiling a lookup table that needs to have 133,784,560 entries, with values ranging from 0 - 7,462 The maximum value of 7,462 can be contained within 13 bits. This gives us a lookup table of around 207 MB. A 16 bit value increases our lookup table size around 50mb more. The extra increase in size of the lookup table is not signi...

Problems with malloc on OS X

Hi there, I have written a some C code running on OS X 10.6, which happens to be slow so I am using valgrind to check for memory leaks etc. One of the things I have noticed whilst doing this: If I allocate memory to a 2D array like this: double** matrix = NULL; allocate2D(matrix, 2, 2); void allocate2D(double** matrix, int nrows, int...

_dyld_start causing leaks in iphone apps

Using the Allocations Instrument on my Iphone Device, I notice in my heapshots that all my heap growth is caused by the _dyld_start caller (of dyld library). Here is an example: Snapshot: UIImageView Heap Growth: 4.83 Kb Still Alive: 103 When I look in the details, all I see is several instances of the following: Object Add: xxxx C...

iPad and memory problems

Hi, is it possible, that when the iPad application is forcibly closed/killed by the iOS becuase of 'out of memory situation', the memory the application allocated is not 100% released? I think that the memory allocated directly by the client is released - there is even HW support for this, but we were observing that if the application i...

static allocated data structures

I'm working on a existing embedded system (memory is limited, Flash is limited, ...) with an RT OS. All data structures have a fixed size and are allocated at "compile time" and are therefore suited for RT. There is no dynamic memory allocation. The programming language is C++, but there is no STL available. I like to replace some of the...

How much processing and memory use does casting take in Java?

Hi all, I am considering whether it is better to have two pointers, one for each object sub class and super, or whether I should just use casting. How much system resources does this use: objectName.functionOne(); ((SubClass) objectName).functionOther(); Is it better than: SuperClass objectA = (SuperClass) getSameInstance(); SubCl...

strsep segmentation faults on different string pointer/array types

Platform: Linux, OSX Compiler: GCC I've got a simple program which is currently confounding me - I know that I'm messing with a couple different kinds of arrays/pointers to produce this problem - its intentional - I'm trying to understand it. The code as listed will compile and run as expected, but changing data4 in the call to strsep(...

App crashes when used with Allocations Instrument

I have seen that my app crashes when used with the Allocation Instrument. When looking at the device logs, I can tell that it is a 'Low memory' crash. My app process in addition to others used by my app were jettisoned. Here is how the device logs look: MyAPP <09da004ccd82e7a2c54e0ea6ab4eab24> 1990 (jettisoned) (active) MobilePhon...

Groovy: Handling large amounts of data with StreamingMarkupBuilder

Hello, The scenario is the following. I have a plain text file which contains 2,000,000 lines with an ID. This list of IDs needs to be converted to a simple XML file. The following code works fine as long as there are only some thousand entries in the input file. def xmlBuilder = new StreamingMarkupBuilder() def f = new File(inputFile)...

Why is my memory layout different?

The following code snippet: void (*foo)(); char X[1]; char Y[10]; could intruitively give me one possible stack layout of: | Y[10] | |---------| | X[1] | |---------| | foo | |---------| I examined this by generating the ASM file using: gcc -S -o stack stack.c Then I oberved that the order of pushing these variables is ...

Sending C strings and vectors to MurmurHash gives inconsistent results.

I'm trying to use MurmurHash (returning 64 bit hashes on a 64bit comoputer) and have sent it the simple 3 letter string 'yes' as follows char* charptr = "yes"; cout << MurmurHash64A(charptr, 3, 10); (where 3 is the length and 10 is the seed) This gives a 64bit hashed response as expected, I can set up more pointers to C strings holdin...

boost::shared_array and aligned memory allocation

In Visual C++, I'm trying to dynamically allocate some memory which is 16-byte aligned so I can use SSE2 functions that require memory alignment. Right now this is how I allocate the memory: boost::shared_array aData(new unsigned char[GetSomeSizeToAllocate()]); I know I can use _aligned_malloc to allocate aligned memory, but will th...

What is faster and more convenient: Hashtable or Dictionary<int, double>()?

Preamble: I'm working at heavy-loaded applicaion that produces large data arrays. I wrote the following class using System; using System.Collections; using System.Collections.Generic; namespace CSharpSampleApplication.Data.CoreObjects { [Serializable] public class CalcItem { pub...

How do I invoke the nothrow version of delete?

I have the following code, which doesn't compile: int *p = new(nothrow) int; delete (nothrow) p; //Error The error I get is: error C2440: 'delete' : cannot convert from 'const std::nothrow_t' to 'void*' Does a nothrow version of delete exist? If so, how can I invoke it? In C++: The Complete Reference, it's given that it exis...