Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

Search the Tips
Tip Bank > Application Design > Memory Management

Memory Management - Page 4

61-80 of 88     Previous     Next
Efficient Array Copying
by Danny Kalev
Suppose you want to assign the contents of a two-dimensional array to another two-dimensional array: ...
Understanding What Memory Alignment Means
by Danny Kalev
Most CPUs require that objects and variables reside at particular offsets in the system's memory. For example, 32-bit processors require a 4-byte integer to reside at a memory address that is ...
Using "Sentry Bytes" to Detect Memory Overruns
by Danny Kalev
One of the most frustrating aspects of debugging is detecting memory overruns. Some compilers (MS Visual C++ for instance) automatically add "sentry bytes" at the ends of every memory block ...
Minimize the Use of Pointers and Dynamic Memory Allocation
by Danny Kalev
Pointer-based operations are less frequently needed than they might seem. For instance, examine this class ...
Accessing a C++ Object in C Code: The Memory Layout of Derived Objects
by Danny Kalev
The Standard does not specify the memory layout of base class subobjects in a derived class. In practice, however, all C++ compilers use the same convention: The base class subobject appears first ...
Resizing Dynamic Array
by DevX Pro
int num = 50; int **stuff; stuff = new int* [num]; for (int i = 0 ; i The code above is copied from another question. Say the above array is a matrix where each row has a number of columns, how do you increase the size of the array to add another row?
What's in an Allocator?
by Danny Kalev
Every STL container uses an allocator that encapsulates the memory model that the specific platform uses. Allocators hide the platform-dependent details such as the size of pointers, memory ...
Placement New Objects Must be Destroyed Explicitly
by Danny Kalev
Objects constructed on a pre-allocated buffer by using placement new must be destroyed explicitly. ...
Array of pointers.
by DevX Pro
I need to pass an array of pointers to a class to a function. The function is: void myFunc(myClass *example[]); The problem is that I need to define the size of this array at run time. I know this is possible with a normal array. For example: int *array; array = new int[size]; where size is a variable. Is it possible to set up an array of pointers in this way? If so how is it done?
Static initialization and free store
by DevX Pro
Is it valid to attempt to allocate (via 'new()') dynamic memory prior to 'main()'? I am working on software that has static *'s to class objects, and through some rather nasty macro expansion, these object ptrs attempt to instantiate themselves via the 'new()' operator. I am working on Irix 6.2 and the software used to work fine under the Irix O32 ABI. When we ported to the N32 ABI, it started seg faulting and Purify reports IPR/IPW fatal errors throughout these static initializers.
Garbage Collector in C++?
by Danny Kalev
A garbage collector is handy, since it eliminates a big source for bugs, runtime crashes and memory leaks. However, garbage collection is not for free; it incurs additional runtime overhead for ...
Placement-New Requires Heap-Allocated Buffers
by Danny Kalev
The placement-new operator constructs an object on a pre-allocated buffer. The pre-allocated buffer has to be allocated on the heap. ...
Dynamic memory allocation
by DevX Pro
How do you dynamically allocate memory for a two-dimensional array? This is what I had, and my g++ compiler didn't like it: int **m; m= new int [100][100];
Placement new
by Danny Kalev
Operator new allocates memory from the heap, on which an object is constructed. Standard C++ also supports placement new operator, which constructs an object on a pre-allocated buffer. This is useful ...
When memory re-allocation is needed, prefer vector<> over C mem-functions
by Danny Kalev
If you're still using the almost deprecated malloc(), free() and realloc() just because you need a dynamic memory container which expands and shrinks upon request, you should seriously consider using ...
Mixing delete and delete[]
by DevX Pro
I am programming with Visual C++ 5.0 and the class library StarView from StarDivision. Looking at the Source from StarView, I found bad code: void** p = new (void*)[100]; ... delete p; Could this be the reason for the following warnings during program execution in debug mode: Could not free object from heap using pointer xyz. Can the library handle this problem and free the objects correctly?
Virtual memory on large dataset
by DevX Pro
I'm working with large multidimensional dataset (> 10 dimensions and > 100,000 points). One particular problem I have is the use of virtual memory (for example, via new). When I input dataset with more than 6 dimensions and 100,000 points, the program halts with the message: "virtual memory exceeded in new()". Can you provide me with some general guidelines when working with large datasets? The program I create uses dynamic linklist structure, a fixsize lookup table (= datasize), and creation of dynamic array in a loop (I use new and delete within the loop so that the memory can be refreshed and reused).
auto_ptr<>: your safe guard against memory leaks
by Danny Kalev
The Standard Library supplies the class template auto_ptr<> which automatically deallocates heap memory. Likewise, local objects are reclaimed in case of exiting their scope or during "stack ...
General Protection Fault
by DevX Pro
#include #include void main() { randomize(); const int max_num=1000; int value[max_num]={0}; const num_word_per_line=8; cout This is a very simple, random numbers generation program. However, I get "General Protection Fault" every time I try to run it. When I change const int max_num=1000; to const int max_num=800;, it works. However, it wouldn't work when max_num is over 800. Can you tell me what causes this error and how can I fix this problem? I'm using Borland C++ 4.5, Windows 95, P200 MMX with 32MB RAM.
Avoid Using malloc() and free() in C++
by Danny Kalev
The use of malloc() and free() functions in a C++ file is not recommended and is even dangerous: ...
61-80 of 88     Previous     Next
Thanks for your registration, follow us on our social networks to keep up-to-date