memory-allocation

Is it OK to use boost::shared ptr in DLL interface?

Is it valid to develop a DLL in C++ that returns boost shared pointers and uses them as parameters? So, is it ok to export functions like this? 1.) boost::shared_ptr<Connection> startConnection(); 2.) void sendToConnection(boost::shared_ptr<Connection> conn, byte* data, int len); In special: Does the reference count work across DLL b...

std::vector reserve method fails to allocate enough memory

Hi, I have a buffer class in my C++ application as follows: class Buffer { public: Buffer(size_t res): _rpos(0), _wpos(0) { _storage.reserve(res); } protected: size_t _rpos, _wpos; std::vector<uint8> _storage; } Sometimes using the constructor fails because its unable to allocate the required memory ...

when does c++ allocate/deallocate string literals

When is the string literal "hello" allocated and deallocated during the lifetime of the program in this example? init(char **s) { *s = "hello"; } int f() { char *s = 0; init(&s); printf("%s\n", s); return 0; } ...

memset, memcpy with new operator

Can I reliably use memset and memcpy operators in C++ with memory been allocated with new? Edited: Yes, to allocate native data type Example BYTE *buffer = 0; DWORD bufferSize = _fat.GetSectorSize(); buffer = new BYTE[bufferSize]; _fat.ReadSector(streamChain[0], buffer, bufferSize); ULONG header = 0; memcpy(&header, buffer, sizeof(...

Memory requirments for large python list

I was doing a foolish thing like from itertools import * rows = combinations(range(0, 1140), 17) all_rows = [] for row in rows: all_rows.append(row) No surprise I run out of memory address space (32 bit python 3.1) My question i, how do I calculate how much memory address space I will need for a large list? In this case the list i...

a library forces global overloads of new/delete on me!

I'm maintaining a plugin (implemented as a dll) for a big closed source application. This has been working fine for years. However, with the latest update to it's SDK the vendor overloaded global operators new and delete. This causes lots of trouble for me. What happens is that my plugin allocates a string. I pass this string into a stat...

Delete operator and arrays

I have an abstract Base class and Derived class. int main () { Base *arrayPtr[3]; for (int i = 0; i < 3; i++) { arrayPtr[i] = new Derived(); } //some fuctions here delete[] arrayPtr; return 0; } I'm not sure how to use the delete operator. If I delete array of base class pointers as shown above, will this call de...

c# structs/classes stack/heap control?

hi! so in c++ it's very easy. you want whatever class/struct to be allocated on the heap, use new. if you want it on the stack, don't use new. in C# we always use the new keyword, and depending on whether it's a struct or a class it's allocated either on the stack or on the heap (structs go to the stack, classes to the heap) - and in s...

Can memory be cleaned up?

I am working in Delphi 5 (with FastMM installed) on a Win32 project, and have recently been trying to drastically reduce the memory usage in this application. So far, I have cut the usage nearly in half, but noticed something when working on a separate task. When I minimized the application, the memory usage shrunk from 45 megs down to...

Do i have to use glDeleteTextures() in the end of the program?

Saw that in some example codes, but ive never used it, unless im dynamically opening new different sized textures etc. So does my OS or something take care of freeing the texture memory when my app is terminated? Or do i have to free it myself ? ...

Why is PermGen space growing?

I've read a few articles, and I understood the following (please correct me and/or edit the question if I'm wrong): The java heap is segmented like this: Young Generation: objects that are created go here, this part is frequently and inexpensively garbage collected Old Generation: objects that survive the garbage collections of the Y...

.Net Why can't I get more than 11GB of allocated memory in a x64 process?

I thought that the maximum user space for a 64bit process was 8TB, but I did a little test and the maximum I could get is 10-11GB. Note: I don't need that much memory in a process, I just want to understand why out of curiosity. Here is my test program: static void Main(string[] args) { List<byte[]> list = new List<byte[]>(); ...

Why is Visual C++ 2010 complaining about 'Using uninitialized memory'?

I've got a function that takes a pointer to a buffer, and the size of that buffer (via a pointer). If the buffer's not big enough, it returns an error value and sets the required length in the out-param: // FillBuffer is defined in another compilation unit (OBJ file). // Whole program optimization is off. int FillBuffer(__int_bcount_opt...

dynamic array IN struct, C

I have looked around but have been unable to find a solution to what must be a well asked question. Here is the code I have: #include <stdlib.h> struct my_struct { int n; char s[] }; int main() { struct my_struct ms; ms.s = malloc(sizeof(char*)*50); } and here is the error gcc gives me: error: invalid use of flexibl...

What will be the memory allocation of this C#.NET code.

using System; class ClassOfInts { public int x; public int y; } class Test { ClassOfInts objClassOfInts; string name; public TestMethod(int p, int q, string s) { objClassOfInts=new ClassofInts; objClassOfInts.x=p; objClassOfInts.y=q; name=s; } } class Main { static Ma...

my C program has a char, and I want it to hold more data, what data type do I substitute for it?

I want to modify a program that grabs images from a camera capture board, now its using a char and says its limited to 1000 images, its early/late and I need sleep, so maybe there is a better way to go about this, but I am thinking maybe I could just substitute all the related data variables with higher capacity data types... right now i...

Garbage Collection and Threads

AFAIK when a GC is doing its thing the VM blocks all running threads -- or at least when it is compacting the heap. Is this the case in modern implementions of the CLR and the JVM (Production versions as of January 2010) ? Please do not provide basic links on GC as I understand the rudimentary workings. I assume global locking is the ...

Does new() allocate memory for the functions of a class also?

class Animal { public: int a; double d; int f(){ return 25;} }; Suppose for the code above, I try to initialize an object, by saying new Animal(), does this new() also allocate memory for the function f()? In other words, what is the difference in memory allocation terms if I had this class instead and did a new Animal() ? : c...

[C] Freeing memory after use

I have a command line C program for which I use the calloc() function to assign some memory for a struct which also has a struct in it with some memory assigned. If I use the free() function to release the memory from the parent struct, will it also release the memory from the child struct? Or should I release the memory from the child...

Using STL Allocator with STL Vectors

Here's the basic problem. There's an API which I depend on, with a method using the following syntax: void foo_api (std::vector<type>& ref_to_my_populated_vector); The area of code in question is rather performance intensive, and I want to avoid using the heap to allocate memory. As a result, I created a custom allocator which alloc...