C++ :: Managing Memory With Multiple Heaps
Apr 15, 2013Is it a common thing to do? Does this tutorial seem legit .... [URL] .....
View 9 RepliesIs it a common thing to do? Does this tutorial seem legit .... [URL] .....
View 9 RepliesI'am creating a 10x10 graph of nodes. Each node is a button object.
Instead of coding the click event procedure for each (As each button will do the same thing when clicked), how would I implement a single click event method for all of the buttons within a Button array.
Picture of the 10x10 grid
EDIT: Each button would return its location (x,y) to the node class.
I'm attempting to write a basic Dijkstra's algorithm using a 10x10 grid.
I wonder are there boost available structures that act pretty much the same as binary heaps of C# in VC++?
like this code snippet in C#
Code:
BinaryHeap<Node> OpenList = new BinaryHeap<Node>();
BinaryHeap<Node> ClosedList = new BinaryHeap<Node>();
Code:
namespace LibAStar {
/// <summary>
/// A binary heap, useful for sorting data and priority queues.
/// </summary>
/// <typeparam name="T"><![CDATA[IComparable<T> type of item in the heap]]>.</typeparam>
public class BinaryHeap<T> : ICollection<T> where T : IComparable<T> {
// Constants
[code].....
My application calls malloc in multiple subroutines, finally releasing all using free. This is done using my zalloc library (see my other post: [URL] .....
Somehow, when the applications tries to detect the available ammount of memory at the end of the test (allocating, freeing, testing), the freemem function gives me about 4-6MB less memory than at the start of the test? (out of 21MB available on the device at the start).
All memory is allocated and freed using the malloc/free routines within the library, with the exception of the SDL functions, which are registered externally on allocation and release.
Organizing and managing a large database of words building semantic relationships between them.
Questions:
1. Is C++ a good language to manage large databases
2. Is there a better language/software solution that can easily manage my database but return output that I could use in C++
3. Is C++ a good language for securing and encryption? If not, where should I look?
look at this code:
#include <iostream>
using namespace std;
class teste
[Code]....
Each time i call "x = new teste();" the previous object is deleted? Does this code cause any sort of memory leak?
My assignment is to write a system for managing a radio station. The code is composed of four classes:
Song: each song has a name, a composer and a singer, and has a few segments: INTRO,VERSE,CHORUS,TRANSITION, while each represents a different length string of chars.
Playlist: a multiset of songs, and a pointer to a RadioStatistics instance (see below).
RadioStation: a set of Songs (will represent the station database), and a list of Playlists, each playlist holds a few songs from the database.
RadioStatistics: can only be instantiate once, this object gather statistics; it has two maps: one that counts how many times a song was played, and second that counts how many times each singer was played. (the key is the song/singer name, and the value is the counter).
The RadioStation has a constant that defines a limit to how many times a song is allowed to be played. whenever a song reaches this limit (meaning, it was played too much), the program needs to skip to the next song in the database.
so, I run this test from main, and the program crashes (or more accuratly get stuck, since the console stays open and the program keeps working until I stop it).
I made a few changes and run the debugger a few times, and was able to focus on the problem.
Song.h:
Code:
#ifndef SONG_H_
#define SONG_H_
#include<iostream>
#include<string>
[Code] ....
I ran a step by step debugger, and found out the problem lays with line 90 in RadioManager.cpp, when the while loop runs its fourth iteration. It crashes when it tries to dereference the iterator, while it points to the fourth playlist in the list.
And here's some more weird stuff: when I comment out line 73 in main.cpp - it works perfectly fine! (line 73 in particular! commenting out any other line in main.cpp didn't worked around the bug!)
I want to develop an application which can host multiple views of explorer (window), where as each window is totally separate from others. So that I can have multiple desktop views through my single explorer. Any built in feature in .NET ?
View 11 Replies View Relatedhow to make subroutines and return multiple arrays.Before that, i wrote my program on matlab. could my program to be structured as following?
<header>
initial value of program;
subroutine1() {
calculating the first work;
return 2 or 3 arrays;
[code].....
I've been working on a function that works like a pipeline of a shell but receives a directory, go over it an search for every file to send it to a filter, something like this in bash "cat dir/* | cmd_1 | cmd_2 | ... | cmd_N", The only problem i have with the code is the redirection of the pipe descriptors.
Code:
int main(int argc, char* argv[]){
char** cmd;
int Number_cmd;
cmd = &(argv[2]); /*list of cmds*/
Number_cmd = argc-2; /*number of cmds*/
}
[code]....
The code is seems to work fine except when i run it with more than one command in example ("./filter DIR wc rev") in this case it returns
wc: standard input: Bad file descriptor
wc: -: Bad file descriptor
0 0 0
I'm using multiple C++ files in one project for the first time. Both have need to include a protected (#ifndef) header file. However, when I do that, I get a multiple definition error.
From what I found from research, adding the word inline before the function fixes the error. Is this the right way to do this, and why does it work? Should I make a habbit of just declaring any function that might be used in two .cpp files as inline?
Say I have 5 vectors of unsigned char each of size 5. I want to take the max of each index and store it in a new vector. What is the most optimal way to accomplish this?
My slow code:
Code:
vector<unsigned char> vec1;
vector<unsigned char> vec2;
vector<unsigned char> vec3;
vector<unsigned char> vec4;
[Code]....
I had a quick question regarding a program I am trying to complete. I have the basics worked out, and everything seems to be done, but I am running into two issues.
1= The program keeps telling me "Run-Time Check Failure #3 - The variable 'order' is being used without being initialized."
and
2= When I reach my output screen I receive "Unhandled exception at 0x7751c41f in CISC 192 Project 3.exe: Microsoft C++ exception: std:Out_of_range at memory location 0x002eefb8.."
While the first one isn't necessarily a deal breaker the second one definitely is.
Code:
// Bookstore Project 3.cpp : Defines the entry point for the console application.
// Declarations
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <istream>
[Code] ....
I'm trying out the gmp library by building a simple pi calculation program (original, I know!). On a million digits of Pi I've debugged the program and seem to have about a megabyte too much of memory at the end of the program (I start with around 250k before any allocation begins and end at around 1200).
int main(int argc, char *argv[]) {
//set a//
int digitsofpi =1000000;
mpf_set_default_prec(log2(10) *digitsofpi );
mpf_t a;
mpf_init (a);
mpf_set_ui (a,1);
[code].....
I am looking for a way to run a process form memory, without having any executable. The application will be kept inside a resource and will be extracted during run time. It should be then started as a new process. I couldn't find a solution that works also on x64
View 5 Replies View RelatedWe have a proprietary third-party library that we make calls into via an API. Through a series of API calls, this library manipulates specific sets of data. Prior to making these calls, there are some API calls that are necessary in order to initialize the library in preparation for a specific set of data. One of the calls tells the library to allocate some memory and then perform whatever initialization is required. This particular API call returns a pointer to char (char*) that is later used as an argument for a few other API calls. My question is... Is there a way, or maybe some kind of trick, to tell exactly how much memory was allocated? It doesn't matter whether or not the solution (if there is one) is C++ related, or some series of OS commands. FYI: We're running on Redhat Linux 6.2 and using GNU C++ 4.4.6.
View 5 Replies View RelatedSo, it seems I have a bug in my code:
Code:
char *mem = malloc(9), *bottom = malloc(3), *in = "abc";
int position = 2, i;
mem = "onetwo";
printf("OLD mem = %s
", mem);
[Code]....
What I'm trying to do is insert "abc" in the 3rd position of "onetwo". Results would be "oneabctwo", but all I get is crashing.
Is there any way to read RAM memory directly. For say i want to access memory location 0x0100 to 0x120. How to do that. how to declare the variable, is it unsigned int. what is the type of read values it hex or ascii. how t cast it.
View 2 Replies View RelatedI have declared a global variable as pointer. The program performs certain number of iterations. After every iteration, the size of memory required for the pointer changes and this pointer variable is to be accessed by different functions. Now, here is my doubt:If I allocate the memory for this global variable in a function, will the contents of the memory be lost once I exit that function. In my opinion, it should not be the case as the dynamic memory allocation takes place in "heap" and should not be affected by the call of functions.
View 4 Replies View RelatedCode:
int *p, ar[100];
p = (int *)malloc(sizeof ar);
.. *p is a pointer variable, but what means another * here --> (int *)?
I have created a database for music cds:
Code:
#include<stdio.h>
#include<stdlib.h>
#define array
typedef struct cd_database
[Code]....
When I am using malloc instead of arrays the code is not working properly after exit. I have tried alot but can't came up with a way
Code:
# include <stdio.h>
# include <math.h>
# include <stdlib.h>
# include <malloc.h>
}
[code]...
I am compiling it on a 64 BIT ubuntu machine having 64GB ram using gcc 4.6 compiler. I am getting the following output Error allocating memory. But (914*866*2724) is approximately 8 GB, Whats wrong with the code?
I need to use realloc to extend the memory when it goes out of bounds but I am not getting a correct output.
this is how i am trying to realloc
Code:
if(strlen(theString) - strlen(searchFor) + strlen(replace) >= size -1) {
size += 80;
// theString = strcpy(theString,theString);
[Code].....
I am new to C++ language and I am still learning.I'm doing basic stuff to better understand dynamic memory. I was wondering why I keep getting memory issues.*/
#define SIZE 15
class word {
char* str;
public:
[code]....
I'm currently learning templates -- & my logic is in a knot with what I am trying to do which is the following:
-Create a function name load
-Accepts a filename (the filename is a text file of integers)
-Open the file
-Create an array(dynamically allocating an array) filling it with the elements read in from the file & returns the array(so that the return type of the array is a pointer to the element type of the array).
//Header file:
#ifndef BUBBLE_SORT_H
#define BUBBLE_SORT_H
#include <iostream>
template <typename T>
void load(std::string filename, T *&arr, int *size);
[code].....
how to allocate memory when it comes to using templates..
In the code below. I believe I am returning the memory location of the value I am looking for. How can get the value?
main.cpp
int choice = 0;
PlayerMenu *newPM = new PlayerMenu;
File *file = new File;
// Menu for loading, creating or exiting the game
choice = newPM->menuChoices();
PlayerMenu.cpp
[Code] ....
I am not sure how to deference the value so I can get at the value instead of the memory location.