allocation

help with linked lists implementation

Hi, I'm trying to make a Stack using an underlying linked list structure. Maybe I'm wrong, but I'm having trouble with the remove() function. int Stack::remove(){ node* victim = new node; int popped; popped = top->element; victim = top; top = victim->next; delete victim; return popped; } I'm getting glibc ...

C 3d array dynamic memory allocation, question, need help

Hi. I was looking through the web for a way to dynamically allocate space for 3d matrix, say of int type. And i found many sites concerning 2d matrices, and this one http://www.taranets.com/cgi/ts/1.37/ts.ws.pl?w=329;b=286 And there was this example as shown down. I understood all of above examples but this concerning 3d i cannot. Is ...

Pointer allocation vs normal declaration.

Hi, sometimes I see in various C++ programs, objects declared and used like so: object *obj = new object; obj->action(); obj->moreAction(); //etc... Is there any benefit of doing that, instead of simply doing: object obj; obj.action(); obj.moreAction(); //etc ...

What percentage of project hours should be developer development (non-meeting) for maximum output.

I'm working on a typical internal web/database app for a large corporation. By typical, I mean, a project that was projected to be 4 months and $300,000 looks like its going to be 9 months and $1,000,000. IMHO, one reason for gross over-run is the ratio of functional people to developers, 3.5 to 2 (PM, BA, QA, and a scrum master that c...

Any tool to find size of memory allocated dynamically using malloc/realloc?

Hi, I have a MS-Visual Studio 2005 workspace having all c code. This application(exe) allocates memory dynamically from heap using malloc and realloc. I want to calculate the maximum size allocated size allocated on heap using malloc/realloc by this application program when i run particular test case. I do not want to change the code b...

Memory allocation while insertion into a map

#include <stdio.h> #include <stdlib.h> #include <memory.h> #include <vector> #include <string> #include <iostream> #include <map> #include <utility> #include <algorithm> void * GetMemory(size_t n) { void *ptr = malloc(n); printf("getMem n %d ptr 0x%x\n", n, reinterpret_cast<unsigned int> (ptr)); return ptr; } void FreeMemory(vo...

Memory allocation problem C/Cpp Windows critical error

Hi! I have a code that need to be "translated" from C to Cpp, and i cant understand, where's a problem. There is the part, where it crashes (windows critical error send/dontSend): nDim = sizeMax*(sizeMax+1)/2; printf("nDim = %d sizeMax = %d\n",nDim,sizeMax); hamilt = (double*)malloc(nDim*sizeof(double)); printf("End hamilt alloc. ...

Retain, alloc, properties ... Topic to make your Obj-c life easier !

Hey everyone, The more I code, the more I get lost ... so I decided to create a topic entirely dedicated to the memory management for me (and others) not to waste hours understanding obj-c basics ... I'll update it as new questions are asked ! Okay below is some examples : // myArray is property (retain) myArray = otherArray; //myAr...

Memory Allocation for a Map with a fixed number of insertions

I want to insert n elements into a map where n is known ahead of time. I do not want memory allocation at each insertion. I want all memory allocation at the beginning. Is there a way to do this? If so, how? Will writing some sort of memory allocator help? I ran GMan's code and got the following output. GetMem is printed from a call to ...

Malloc inside another function (ANSI C)

Hi I'll go straight to it. I'm working on an assignment, where I suddenly ran into trouble. I have to allocate a struct from within another function, obviously using pointers. I've been staring at this problem for hours and tried in a million different ways to solve it. This is some sample code (very simplified): ... some_struct s; pr...

.NET DB Query Without Allocations?

I have been given the task of re-writing some libraries written in C# so that there are no allocations once startup is completed. I just got to one project that does some DB queries over an OdbcConnection every 30 seconds. I've always just used .ExecuteReader() which creates an OdbcDataReader. Is there any pattern (like the SocketAsyn...

What is the difference among NSString alloc:initWithCString versus stringWithUTF8String?

I thought these two methods were (memory allocation-wise) equivalent, however, I was seeing "out of scope" and "NSCFString" in the debugger if I used what I thought was the convenient method (commented out below) and when I switched to the more explicit method my code stopped crashing! Notice that I am getting the string that is being s...

C++ Static array vs. Dynamic array?

What is the difference between a static array and a dynamic array in C++? I have to do an assignment for my class and it says not to use static arrays, only dynamic arrays. I've looked in the book and online, but I don't seem to understand. I thought static was created at compile time and dynamic at runtime, but I might be mistaken th...

C# memory allocation

Does using operator new in c# might fail (if it requires a large memory for example)? -Solved- And how to discover it? -Solved- What other failures new operator might throw? Thanks ...

dynamically created arrays

My task consists of two parts. First I have to create globbal char array of 100 elements, and insert some text to it using cin. Afterwards calculate amount of chars, and create dedicated array with the length of the inputted text. I was thinking about following solution : char[100]inputData; int main() { cin >> inputData >> endl;...

What happens when you deallocate a pointer twice or more in C++?

int main(){ Employee *e = new Employee(); delete e; delete e; ... delete e; return 0; } ...

HeapCreate, HeapAlloc in Linux, private allocator for Linux

Hi, In Windows, for very demanding applications, a programmer may use HeapCreate, HeapAlloc in order to better manage and control the allocation of memory- speed it up (aka private allocators). What is the equivalent in Linux c++ programming? ...

Dynamic stack allocation in C++

I want to allocate memory on the stack. Heard of _alloca / alloca and I understand that these are compiler-specific stuff, which I don't like. So, I came-up with my own solution (which might have it's own flaws) and I want you to review/improve it so for once and for all we'll have this code working: /*#define allocate_on_stack(pointe...

how to make array of class objects using dynamic allocation in c#?

hi, i made a class named x; so i want to make array of it using dynamic allocation x [] myobjects = new x(); but it gives me that error Cannot implicitly convert type 'ObjAssig4.x' to 'ObjAssig4.x[]' i know it's dump question but i am a beginner thanks ...

SQL Scenario of allocating ids to user

I have an sql scenario as follows which I have been trying to improve. There is a table 'Returns' which is having ids of the returned goods against a shop for an item. Its structure is as below. Returns ------------------------- Return ID | Shop | Item ------------------------- 1 Shop1 Item1 2 Shop1 Item1 3 ...