I came up with this as a quick solution to a debugging problem - I have the pointer variable and its type, I know it points to an array of objects allocated on the heap, but I don't know how many. So I wrote this function to look at the cookie that stores the number of bytes when memory is allocated on the heap.
template< typename T >
i...
In almost all of the books I read and examples I go through I see pointers initialized this way. Say that I have a class variable NSString *myString that I want to initialize. I will almost always see that done this way:
-(id)init {
if (self = [super init]) {
NSString *tempString = [[NSString alloc] init];
self.myS...
Is there a utility (for Windows) that uses up memory so I can create a JVM "could not reserve enough space for object heap" error?
I want to use up this memory in a process outside of the JVM.
...
Occasionally you meet bugs that are reproducible only in release builds and/or only on some machines. A common (but by no means only) reason is uninitialized variables, that are subject to random behaviour. E.g, an uninitialized BOOL can be TRUE most of the time, on most machines, but randomly be initialized as FALSE.
What I wish I wou...
This is my scenario, Im trying to overload new and delete globally. I have written my allocator class in a file called allocator.h. And what I am trying to achieve is that if a file is including this header file, my version of new and delete should be used.
So in a header file "allocator.h" i have declared the two functions
extern voi...
Every stl container take an allocator as a parameter:
template < class T, class Allocator = allocator<T> > class vector;
If you write your own class It is possible to use your own allocator.
But is it possible to write your own allocator without using templates?
For example, writing this function is not easy if you are not allowed to...
vector< int > vect;
int *int_ptr = new int(10);
vect.push_back( *int_ptr );
I under stand that every "new" needs to be followed by a "delete" at some point but does the clear() method clean this memory?
What about this method of doing the same thing:
vector< int > vect;
int int_var = 10;
vect.push_back( int_var );
From what I under...
I'm sure you (pros) can identify the bug's' in my code, I also would appreciate any other comments on my code.
BTW, the code crashes after I run it.
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
typedef struct
{
int x;
int y;
} Location;
typedef struct
{
bool walkable;
unsigned char walked; // number of...
I have a Visual Studio 2008 Windows Mobile 6 C++ application that is using an API that requires the use of LocalAlloc(). To make my life easier, I created an implementation of a standard allocator that uses LocalAlloc() internally:
/// Standard library allocator implementation using LocalAlloc and LocalReAlloc
/// to create a dynamical...
I have a 2GB RAM and running a memory intensive application and going to low available physical memory state and system is not responding to user actions, like opening any application or menu invocation etc.
How do I trigger or tell the system to swap the memory to pagefile and free physical memory?
I'm using Windows XP.
If I run the s...
Hello,
gcc 4.4.3 c89
I have the following source code. And getting a stack dump on the printf.
char **devices;
devices = malloc(10 * sizeof(char*));
strcpy(devices[0], "smxxxx1");
printf("[ %s ]\n", devices[0]); /* Stack dump trying to print */
I am thinking that this should create an char array like this.
devices[0]
devices[1]
d...
If a class is declared as follows:
class MyClass
{
char * MyMember;
MyClass()
{
MyMember = new char[250];
}
~MyClass()
{
delete[] MyMember;
}
};
And it could be done like this:
class MyClass
{
char MyMember[250];
};
How does a class gets allocated on heap, like if i do MyClass * Mine = new MyClass();
Does th...
We have a couple of win 2000 boxes with com+ and we're occasionally getting "insufficient memory to perform that operation" errors with the dtsearch.dtengine dll. Since it's registered in com+ I was hoping there was a way to limit the amount of memory it used and then recycle it once it hits that but I can't seem to find a way to do tha...
Hi
I have a C++ program running under linux. Is it possible to track its memory usage from the code? I am allocating new objects and running out of memory, so I want to keep track of how quickly I am using memory.
Thanks
...
I am parsing using a pretty large grammar (1.1 GB, it's data-oriented parsing). The parser I use (bitpar) is said to be optimized for highly ambiguous grammars. I'm getting this error:
1terminate called after throwing an instance of 'std::bad_alloc'
what(): St9bad_alloc
dotest.sh: line 11: 16686 Aborted bitpar -p -b 1...
Hi,
I want to create a custom malloc which allocates memory blocks within a given address range.
I am writing a pthreads application in which threads are bound to unique cores on a many-core machine. The memory controllers are statically mapped, so that certain range of addresses on main memory are electrically closer to a core.
I want...
For this code:
#include<stdio.h>
void hello() { printf("hello\n"); }
void bye() { printf("bye\n"); }
int main() {
printf("%p\n", hello);
printf("%p\n", bye);
return 0;
}
output on my machine:
0x80483f4
0x8048408
[second address is bigger in value]
on Codepad
0x8048541
0x8048511
[second address is smaller in v...
Hi all,
Frequent visitor but first post here on StackOverflow, I'm hoping that you guys might be able to help me out with this. I'm fairly new to Obj-C and XCode, and I'm faced with this really... weird... problem. Googling hasn't turned up anything whatsoever. Basically, I get an EXC_BAD_ACCESS signal on a line that doesn't do any dere...
Hey there, I'm writing a template container class and for the past few hours have been trying to allocate new memory for extra data that comes into the container (...hit a brick wall..:| )
template <typename T>
void Container<T>::insert(T item, int index){
if ( index < 0){
cout<<"Invalid location to insert " << index << endl...
Question:
Do all CLR value types, including
user-defined structs, live on the
evaluation stack exclusively, meaning
that they will never need to be
reclaimed by the garbage-collector, or
are there cases where they are
garbage-collected?
Background:
I have previously asked a question on SO about the impact that a fluent...