Search Results

Search found 870 results on 35 pages for 'allocation'.

Page 12/35 | < Previous Page | 8 9 10 11 12 13 14 15 16 17 18 19  | Next Page >

  • Do classes which have a vector has a member have memory issues

    - by user263766
    I am just starting out C++, so sorry if this is a dumb question. I have a class Braid whose members are vectors. I have not written an assignment operator. When I do a lot of assignments to an object of the type Braid, I run into memory issues :- 0 0xb7daff89 in _int_malloc () from /lib/libc.so.6 #1 0xb7db2583 in malloc () from /lib/libc.so.6 #2 0xb7f8ac59 in operator new(unsigned int) () from /usr/lib/libstdc++.so.6 #3 0x0804d05e in __gnu_cxx::new_allocator<int>::allocate (this=0xbf800204, __n=1) at /usr/lib/gcc/i686-pc-linux-gnu/4.4.3/../../../../include/c++/4.4.3/ext/new_allocator.h:89 #4 0x0804cb0e in std::_Vector_base<int, std::allocator<int> >::_M_allocate (this=0xbf800204, __n=1) at /usr/lib/gcc/i686-pc-linux-gnu/4.4.3/../../../../include/c++/4.4.3/bits/stl_vector.h:140 #5 0x0804c086 in _Vector_base (this=0xbf800204, __n=1, __a=...) at /usr/lib/gcc/i686-pc-linux-gnu/4.4.3/../../../../include/c++/4.4.3/bits/stl_vector.h:113 #6 0x0804b4b7 in vector (this=0xbf800204, __x=...) at /usr/lib/gcc/i686-pc-linux-gnu/4.4.3/../../../../include/c++/4.4.3/bits/stl_vector.h:242 #7 0x0804b234 in Braid (this=0xbf800204) at braid.h:13 #8 0x080495ed in Braid::cycleBraid (this=0xbf8001b4) at braid.cpp:191 #9 0x080497c6 in Braid::score (this=0xbf800298, b=...) at braid.cpp:251 #10 0x08049c46 in Braid::evaluateMove (this=0xbf800468, move=1, pos=0, depth=2, b=...) I suspect that these memory issues are because the vectors are getting resized. What I want to know is whether objects of type Braid automatically expand when its members expand? he code I am writing is really long so I will post the section which is causing the problems. Here is the relevant section of the code :- class Braid { private : vector<int> braid; //Stores the braid. int strands; vector < vector<bool> > history; vector < vector<bool> > CM; public : Braid () : strands(0) {} Braid operator * (Braid); Braid* inputBraid(int,vector<int>); int printBraid(); int printBraid(vector<vector<int>::iterator>); vector<int>::size_type size() const; ..... ..... } Here is the function which causes the issue :- int Braid::evaluateMove(int move,int pos,int depth,Braid b) { int netscore = 0; Braid curr(*this); curr = curr.move(move,pos); netscore += curr.score(b); while(depth > 1) { netscore += curr.evaluateMove(1,0,depth,b); netscore += curr.evaluateMove(2,0,depth,b); for(int i = 0; i < braid.size();++i) { netscore += curr.evaluateMove(3,i,depth,b); netscore += curr.evaluateMove(4,i,depth,b); netscore += curr.evaluateMove(5,i,depth,b); curr = curr.cycleBraid(); netscore += curr.evaluateMove(6,0,depth,b); } --depth; } return netscore; }

    Read the article

  • What is the best solution to replace a new memory allocator in an existing code?

    - by O. Askari
    During the last few days I've gained some information about memory allocators other than the standard malloc(). There are some implementations that seem to be much better than malloc() for applications with many threads. For example it seems that tcmalloc and ptmalloc have better performance. I have a C++ application that uses both malloc and new operators in many places. I thought replacing them with something like ptmalloc may improve its performance. But I wonder how does the new operator act when used in C++ application that runs on Linux? Does it use the standard behavior of malloc or something else? What is the best way to replace the new memory allocator with the old one in the code? Is there any way to override the behavior or new and malloc or do I need to replace all the calls to them one by one?

    Read the article

  • C#. Struct design. Why 16 byte is recommended size?

    - by maxima120
    I read Cwalina book (recommendations on development and design of .NET apps). He says that good designed struct has to be less than 16 bytes in size (for performance purpose). My questions is - why exactly is this? And (more important) can I have larger struct with same efficiency if I run my .NET 3.5 (soon to be .NET 4.0) 64-bit application on i7 under Win7 x64 (is this limitation CPU / OS based)? Just to stress again - I need as efficient struct as it is possible. I try to keep it in stack all the time, the application is heavily multi-threaded and runs on sub-millisecond intervals, the current size of the struct is 64 byte.

    Read the article

  • Reserved Memory Addresses?

    - by Nate
    Is there a list of reserved memory addresses out there - a list of addresses that the memory of a user-space program could never be allocated to? I realize this is most likely per-OS or per-architecture, but I was hoping someone might know some of the more common OSes and Arches. I could only dig one up for a few versions of windows: for windows NT,2k and XP that would be: 0x00000000 - 0x0000ffff - lowest page is protected to simplify debugging 0x00001000 - 0x7ffeffff - memory area for your application 0x7fff0000 - 0x7fffffff - protected area to keep memory-functions from damaging the following part 0x80000000 - 0xffffffff - memory where the system including drivers and so on is located Anyone know about for Linux, or BSD (or anything else, for that matter)?

    Read the article

  • How does C free() work?

    - by slee
    #include <stdio.h> #include <stdlib.h> int * alloc() { int *p = (int *)calloc(5,4); printf("%d\n",p); return p; } int main() { int *p = alloc(); free(p); printf("%d\n",p); p[0] = 1; p[1] = 2; printf("%d %d\n",p[0],p[1]); } As to the code segment, I allocate 5 ints,first. And then I free the memory. When I printf p, why does p sill have a value same to the memory address allocated first? And I also can assign value to p[0] and p[1]. Does this mean free() do nothing? Once I allocate memory, I can use later though I have freed it.

    Read the article

  • Allocating memory for a array to char pointer

    - by nunos
    The following piece of code gives a segmentation fault when allocating memory for the last arg. What am I doing wrong? Thanks. int n_args = 0, i = 0; while (line[i] != '\0') { if (isspace(line[i++])) n_args++; } for (i = 0; i < n_args; i++) command = malloc (n_args * sizeof(char*)); char* arg = NULL; arg = strtok(line, " \n"); while (arg != NULL) { arg = strtok(NULL, " \n"); command[i] = malloc ( (strlen(arg)+1) * sizeof(char) ); strcpy(command[i], arg); i++; } Thanks.

    Read the article

  • Which to use - "operator new" or "operator new[]" - to allocate a block of raw memory in C++?

    - by sharptooth
    My C++ program needs a block of uninitialized memory. In C I would use malloc() and later free(). In C++ I can either call ::operator new or ::operator new[] and ::operator delete or operator delete[] respectively later. Looks like both ::operator new and ::operator new[] have exactly the same signature and exactly the same behavior. The same for ::operator delete and ::operator delete[]. The only thing I shouldn't do is pairing operator new with operator delete[] and vice versa - undefined behavior. Other than that which pair do I choose and why?

    Read the article

  • allocating extra memory for a container class.

    - by sil3nt
    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; return; } if (index < sizeC){ //copying original array so that when an item is //placed in the middleeverything else is shifted forward T *arryCpy = 0; int tmpSize = 0; tmpSize = size(); arryCpy = new T[tmpSize]; int i = 0, j = 0; for ( i = 0; i < tmpSize; i++){ for ( j = index; j < tmpSize; j++){ arryCpy[i] = elements[j]; } } //overwriting and placing item and location index elements[index] = item; //copying back everything else after the location at index int k = 0, l = 0; for ( k =(index+1), l=0; k < sizeC || l < (sizeC-index); k++,l++){ elements[k] = arryCpy[l]; } delete[] arryCpy; arryCpy = 0; } //seeing if the location is more than the current capacity //and hence allocating more memory if (index+1 > capacityC){ int new_capacity = 0; int current_size = size(); new_capacity = ((index+1)-capacityC)+capacityC; //variable for new capacity T *tmparry2 = 0; tmparry2 = new T[new_capacity]; int n = 0; for (n = 0; n < current_size;n++){ tmparry2[n] = elements[n]; } delete[] elements; elements = 0; //copying back what we had before elements = new T[new_capacity]; int m = 0; for (m = 0; m < current_size; m++){ elements[m] = tmparry2[m]; } //placing item elements[index] = item; } else{ elements[index] = item; } //increasing the current count sizeC++; my testing condition is Container cnt4(3); and as soon as i hit the fourth element (when I use for egsomething.insert("random",3);) it crashes and the above doesnt work. where have I gone wrong?

    Read the article

  • Can I switch the Visual C++ runtime to another heap?

    - by sharptooth
    My program uses a third party dynamic link library that has huge memory leaks inside. Both my program and the library are Visual C++ native code. Both link to the Visual C++ runtime dynamically. I'd like to force the library into another heap so that all allocations that are done through the Visual C++ runtime while the library code is running are done on that heap. I can call HeapCreate() and later HeapDestroy(). If I somehow ensure that all allocations are done in the new heap I don't care of the leaks anymore - they all go when I destroy the second heap. Is it possible to force the Visual C++ runtime to make all allocations on a specified heap?

    Read the article

  • How does the CLR (.NET) internally allocate and pass around custom value types (structs)?

    - by stakx
    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 interface has on the runtime performance of a .NET application. I was particuarly worried that creating a large number of very short-lived temporary objects would negatively affect runtime performance through more frequent garbage-collection. Now it has occured to me that if I declared those temporary objects' types as struct (ie. as user-defined value types) instead of class, the garbage collector might not be involved at all if it turns out that all value types live exclusively on the evaluation stack. What I've found out so far: I did a brief experiment to see what the differences are in the CIL generated for user-defined value types and reference types. This is my C# code: struct SomeValueType { public int X; } class SomeReferenceType { public int X; } . . static void TryValueType(SomeValueType vt) { ... } static void TryReferenceType(SomeReferenceType rt) { ... } . . var vt = new SomeValueType { X = 1 }; var rt = new SomeReferenceType { X = 2 }; TryValueType(vt); TryReferenceType(rt); And this is the CIL generated for the last four lines of code: .locals init ( [0] valuetype SomeValueType vt, [1] class SomeReferenceType rt, [2] valuetype SomeValueType <>g__initLocal0, // [3] class SomeReferenceType <>g__initLocal1, // why are these generated? [4] valuetype SomeValueType CS$0$0000 // ) L_0000: ldloca.s CS$0$0000 L_0002: initobj SomeValueType // no newobj required, instance already allocated L_0008: ldloc.s CS$0$0000 L_000a: stloc.2 L_000b: ldloca.s <>g__initLocal0 L_000d: ldc.i4.1 L_000e: stfld int32 SomeValueType::X L_0013: ldloc.2 L_0014: stloc.0 L_0015: newobj instance void SomeReferenceType::.ctor() L_001a: stloc.3 L_001b: ldloc.3 L_001c: ldc.i4.2 L_001d: stfld int32 SomeReferenceType::X L_0022: ldloc.3 L_0023: stloc.1 L_0024: ldloc.0 L_0025: call void Program::TryValueType(valuetype SomeValueType) L_002a: ldloc.1 L_002b: call void Program::TryReferenceType(class SomeReferenceType) What I cannot figure out from this code is this: Where are all those local variables mentioned in the .locals block allocated? How are they allocated? How are they freed? Why are so many anonymous local variables needed and copied to-and-fro only to initialize my two local variables rt and vt?

    Read the article

  • Static variables within functions in C++ - allocated even if function doesn't run?

    - by John C
    I've been reading up on C++ on the Internet, and here's one thing that I haven't been quite able to find an answer to. I know that static variables used within functions are akin to globals, and that subsequent invocations of that function will have the static variable retain its value between calls. However, if the function is never claled, does the static variable get allocated? Thanks

    Read the article

  • safe structures embedded systems

    - by user405633
    I have a packet from a server which is parsed in an embedded system. I need to parse it in a very efficient way, avoiding memory issues, like overlapping, corrupting my memory and others variables. The packet has this structure "String A:String B:String C". As example, here the packet received is compounded of three parts separated using a separator ":", all these parts must be accesibles from an structure. Which is the most efficient and safe way to do this. A.- Creating an structure with attributes (partA, PartB PartC) sized with a criteria based on avoid exceed this sized from the source of the packet, and attaching also an index with the length of each part in a way to avoid extracting garbage, this part length indicator could be less or equal to 300 (ie: part B). typedef struct parsedPacket_struct { char partA[2];int len_partA; char partB[300];int len_partB; char partC[2];int len_partC; }parsedPacket; The problem here is that I am wasting memory, because each structure should copy the packet content to each the structure, is there a way to only save the base address of each part and still using the len_partX.

    Read the article

  • Char * reallocation in C++

    - by JTom
    Hi, I need to store a certain amount of data in the "char *" in C++, because I want to avoid std::string to run out of memory, when exceeding max_size(). But the data comes in data blocks from the network so I need to use reallocation every time I get the data block. Is there any elegant solution for char * reallocation and concatenation in C++?

    Read the article

  • How is an array stored in memory?

    - by George
    In an interest to delve deeper into how memory is allocated and stored, I have written an application that can scan memory address space, find a value, and write out a new value. I developed a sample application with the end goal to be able to programatically locate my array, and overwrite it with a new sequence of numbers. In this situation, I created a single dimensional array, with 5 elements, e.g. int[] array = new int[] {8,7,6,5,4}; I ran my application and searched for a sequence of the five numbers above. I was looking for any value that fell between 4 and 8, for a total of 5 numbers in a row. Unforuntately, my the sequential numbers in my array matched hundreds of results, as the numbers 4 through 8, in no particular sequence happened to be next to each other, in memory, in many situations. Is there any way to distinguish that a set of numbers within memory, represents an array, not simply integers that are next to each other? Is there any way of knowing that if I find a certain value, that the matching values proceeding it are that of an array? I would assume that when I declare int[] array, its pointing at the first address of my array, which would provide some kind of meta-data to what existed in the array, e.g. 0x123456789 meta-data, 5 - 32 bit integers 0x123456789 + 32 "8" 0x123456789 + 64 "7" 0x123456789 + 96 "6" 0x123456789 + 128 "5" 0x123456789 + 160 "4" Am I way off base?

    Read the article

  • Hoard allocator not "working"?

    - by Cowboy
    I'm trying to Hoard allocator to work, but it seems it doesn't. I have a benchmark application that does a lot of dynamic memory management. The execution time for Hoard and glibc memory manager is the same. It makes me wonder if I'm doing the right thing. What I do is... export LD_PRELOAD="/path/libhoard.so" g++ main.cpp -O3 -o bm -lpthread -lrt Shouldn't I have to link to Hoard allocator? Does it matter what path (in LD_PRELOAD) is, or can I have whatever path? I'm running Ubuntu 8.04, and g++ 4.2.4 Cheers

    Read the article

  • How to find out where my memory is going

    - by the_mandrill
    I've got the situation where the cycle of loading and then closing a document eats up a few Mb of RAM. This memory isn't being leaked as something owns it and cleans it up when the app exits (Visual Leak Detector and the Mac Leaks tool show agreement on this). However, I'd like to find out where it's going. I'm assuming it's some sort of cache in the application that gets populated when the document loads but not freed when the document is closed. Which methods or tools could I use to find out where these allocations are being made?

    Read the article

  • Better variant of getting the output dinamically-allocated array from the function?

    - by Raigomaru
    Here is to variants. First: int n = 42; int* some_function(int* input) { int* result = new int[n]; // some code return result; } void main() { int* input = new int[n]; int* output = some_function(input); delete[] input; delete[] output; } Here the function returns the memory, allocated inside the function. Second variant: int n = 42; void some_function(int* input, int* output) { // some code } void main() { int* input = new int[n]; int* output = new int[n]; some_function(input, output); delete[] input; delete[] output; } Here the memory is allocated outside the function. Now I use the first variant. But I now that many built-in c++ functions use the second variant. The first variant is more comfortable (in my opinion). But the second one also has some advantages (you allocate and delete memory in the same block). Maybe it's a silly question but what variant is better and why?

    Read the article

  • Filling in uninitialized array in java? (or workaround!)

    - by AlexRamallo
    Hello all, I'm currently in the process of creating an OBJ importer for an opengles android game. I'm relatively new to the language java, so I'm not exactly clear on a few things. I have an array which will hold the number of vertices in the model(along with a few other arrays as well): float vertices[]; The problem is that I don't know how many vertices there are in the model before I read the file using the inputstream given to me. Would I be able to fill it in as I need to like this?: vertices[95] = 5.004f; //vertices was defined like the example above or do I have to initialize it beforehand? if the latter is the case then what would be a good way to find out the number of vertices in the file? Once I read it using inputstreamreader.read() it goes to the next line until it reads the whole file. The only thing I can think of would be to read the whole file, count the number of vertices, then read it AGAIN the fill in the newly initialized array. Is there a way to dynamically allocate the data as is needed?

    Read the article

< Previous Page | 8 9 10 11 12 13 14 15 16 17 18 19  | Next Page >