C++ :: Memory Usage And Algorithm Efficiency?

Jan 27, 2013

How can I check how much memory my program is using? I have an assignment which asks me to make sure I'm not exceeding some amount of memory but I don't know how I'd do that on Windows 7.

Also, my program parses through a text file and puts each word in a vector so that I can later go through the vector and "locate" where the nth occurrence of a word is by keeping track of a counter and incrementing the counter each time I see the word in the vector. Is this a vector a bad data structure for this? I'm aiming at keeping the efficiency at less than O(n^2).

View 9 Replies


ADVERTISEMENT

Visual C++ :: Get Maximum Memory Usage Of App?

Apr 21, 2013

I use Visual C++ to write a native C++ application. How to know the maximum memory it will use during its execution?

View 5 Replies View Related

C++ :: Memory Usage Of A Program With CLASS And Without CLASS?

Nov 6, 2014

I developing a C++ Program to deal with huge data computation. I am using Pointers to hold the data during computation. Current program i developed without using CLASS.

I would like to ask that will the memory usage will be reduced and computational time will be shortened if I modified my program implementing the CLASS into it ?

View 1 Replies View Related

C++ :: Memory Allocation Recursive Algorithm

Dec 27, 2014

I've been working on a matrix class and I ran into a problem in writing my matrix class. I keep getting 0 as a determinant and with some debugging, I found that I was losing allocated data or something similar. This algorithm I'm pretty sure works because I used this same algorithm in a function I made in python. [URL] .... That's where I found the algorithm.

/*template <class T>
double Matrix<T>::det(T* array, size_t dim, bool recursion)*/
double det(T* array = NULL, size_t dim = 0, bool recursion = false) {
if (recursion == false) {
if (m != n) {
return 0;

[Code] .....

View 2 Replies View Related

C :: Sorting Algorithm With Dynamic Memory Allocation

Nov 17, 2013

I am fairly new to dynamic memory allocation and I keep getting a segmentation fault in this code of mine. This is what the method should do:void sort StringsByReversePoints(char **myWords): This function sorts the char* values (i.e. strings) of myWords in descending order of point value by calling getWordPoints as a helper function and comparing adjacent words. This simple (but inefficient) sorting algorithm starts at the beginning of myWords array and sweeps to the end comparing adjacent values and swapping if they are out of order. After N (length of the array) sweeps the array is fully sorted. Note that efficiency can be improved by a factor of 2 by shortening each successive sweep by one, since the first sweep will have guaranteed the minimum point value word is the last element of the array, the next sweep guarantees the last two elements are correct, and so on....Additionally, if a given sweep results in zero swaps then the array is sorted and you can return immediately.

View 5 Replies View Related

C++ :: How To Criticize Code And Test It For Efficiency

Jan 12, 2015

- When I need to code something, what is the process I should go through to design any algorithm(s), and solve the problem in the most efficient/flexible way? At the moment, I just think up a way of solving it and if it works I will use the code in my current project, but as I have found out from some of my larger projects, this definitely is not the way to go!

- How can I criticize my own code? Again, if I write some code that works I'll keep it. Go through the code and look out for optimizations or refactor the code? Which leads to my last question...

- How can I test my code for efficiency? What are the best ways of testing algorithms (etc) that I have added to see if they are fast enough? Of course, it will probably involve some kind of timer, but how will I be able to tell if X milliseconds is a good enough time?

View 4 Replies View Related

C :: Static Variable Usage

Dec 27, 2013

I was exploring static variable by writing code snippets. I tried below code and it ended up throwing error saying "error: storage class specified for parameter 'b'"

Why static cannot be used in func() ?

Code:
int main() {
int a;
a=5;
func(a);
printf("%d",a);
return 0; }

void func(static int b)
{b=6;
printf("%d",b); }

View 7 Replies View Related

C :: Vector Usage In Codes

Sep 19, 2014

Now i am utilizing vectors in my codes.If i want to make a vector and i use #define to put a limit on the amount of variables it can contain. Until now i can do that. But let's suppose that i put 40 variables as its max capacity, but an user just needs to use only 12 or 14 variables. Put a rule that if someone has finished inserting his data and he is yet to fill the whole capacity of the vector the code.As to say : "If case you want to end press 0" .Edited : My computer has windows 7 and i took Codeblocks as my editor.

View 2 Replies View Related

C++ :: Check CPU / RAM USAGE / Temperature

Nov 1, 2014

I want to make an application that will check CPU/RAM USAGE and CPU TEMPERATURE and if it meets some requirements it will restart your system or do something else..but my problem is:

1) How do i get that info? (i know that in VB.net there is an easy way) but in C/C++ or Java?

2) Is it possible though a C program to execute a command and parse that info to your program?

I am mainly interested for windows but i need also info for linux too..

View 4 Replies View Related

C++ :: Monitor Cpu Usage While App Is Running

Jul 15, 2012

I am working on a parallel processing server/client app with a multi-threaded server and several data processing clients, each their own process. I am trying to optimize some of the parameters, such as the size of the chunks that are read, processed, and output, and also some of the timeout values and such. I can track the time to finish a given task well enough, but it would be really nice to be able to track the cpu use. When CPU use is near 100% (on all cores) for the entire run, that is a good sign. I have noticed that with some combinations of parameters, CPU drops quite a bit for long stretches, which is not such a good sign. This app process large input files (2.5GB-65GB so far) and needs to be stable for long periods of time.

Other than sitting and staring at the task manager all day, is there a good way to track/log the CPU usage over runs that take many hours? I know that there are some apps like Everest that chart CPU use, but it would be nice to have something that would write to the same log file I am already using for other program output.

View 1 Replies View Related

C :: Detect CPU Usage And Free RAM On Windows X86 In C?

Feb 20, 2015

I don't use Visual Studio and/or C++ so I would like to do it without them. I found this article c++ - How to determine CPU and memory consumption from inside a process? - Stack Overflow

I tried some lines of code but no one works for me.

Code:

#include "windows.h"
typedef struct _MEMORYSTATUSEX {
DWORD dwLength;

[Code]....

These was just my first tries to work with da MEMORYSTATUSEX.

I would like to find out if there is free memory at least ... (some value) and similar.

View 1 Replies View Related

Visual C++ :: Usage Of Critical Section

Dec 11, 2012

I am using a thread in my application .. A DLL is written for In and Out instructions for hardware ICS and to read FIFO.

My code is

CCriticalSection crdll , crsec ;
UINT ThreadReceiveData(LPVOID param) {
for ( ; ; ) {
if (bTerminate) break; // bTerminate = 1 in Doc template destructor
crdll.Lock();

[Code] ....

I am confused , how and when I should use Ctitical Section ? The program works fine but I am not happy as this is main routine of the program and I have not understood it properly.

View 10 Replies View Related

C++ :: Simple Class Usage Compiler Error

May 12, 2013

Full disclosure: this is an exercise from "Sams Teach Yourself C++ in 24 Hours" by Jesse Liberty and Rogers Candenhead. This refers to Chapter 9 (Hour 9 Activity 1)

I created a class called Point, in Point.h

I created a class called Rectangle in Rectangle.h and Rectangle.cpp

If I create an int main() function in Rectangle.cpp (that includes Rectangle.h), I can compile Rectangle.cpp and run the resulting program. Fine.

Question:

I create a separate file called main.cpp. I include Rectangle.h. But now the compiler complains.

Code:
$ g++ main.cpp -o main
/tmp/cc38JIph.o: In function `main':
main.cpp:(.text+0x26): undefined reference to `Rectangle::Rectangle(int, int, int, int)'
main.cpp:(.text+0x32): undefined reference to `Rectangle::getArea() const'
collect2: ld returned 1 exit status If I can create a class in Point.h and use it in Rectangle.h, why can I not just use Rectangle in main.cpp?

And the files, of course:

file: main.cpp
Code:
#include <iostream>
#include "Rectangle.h"
using std::cout;
using std::endl;

[Code] .....

View 3 Replies View Related

C++ :: Array Char Rotation And Arrow Key Usage

Apr 27, 2013

I am doing a project for a class which involves making a game where there is an arrray that holds a player (you) and a zombie (comp). The player is suppose to be able to turn clockwise or counter clockwise, move forward, and backward and shoot. Im having trouble trying to rotate the char in an array. I am also trying to switch from using the W,S,D,A to the arrow keys but doesnt seem to work.

#include <iostream>
#include <windows.h>
#include "color.h"
using namespace std;
using namespace Petter;
const int COL = 15;
void initBoard(char[][COL], int, int);

[Code] ....

View 5 Replies View Related

C# :: High RAM Usage On Postback Caused By Datatable

Dec 23, 2014

I basically have a listbox that has postcode areas i.e : AE,CW,GU etc etc.

The user selects this and then a postback occurs - an sql statement is builts and a database query operation is performed and the results are returned to a datatable called tempdata.

So far so good. I then need to loop through this datatable and copy the records to my main viewstate datatable which is the datasource for google maps api.

DataTable tempstore = GetData(querystring, "");
//check tempstore has rows otherwise add defaultcust as default otherwise map will be blank
if (tempstore.Rows.Count == 0)
{

[Code].....

So my main datatable can grow and grow as users add more postcodes. However when it gets to around 500 rows or so I get a huge memory spike only on postback and then it settles back down.

My ram usage goes from 2gb to 3gb and if even more postcodes is selected it maxes the memory and crashes my pc.

If I remove the:

dtpc.Importrow(row);

the memory spike goes completely, obviously because the main datatable has no rows. I thought you only run into memory issues when you have thousands of rows?

View 1 Replies View Related

C++ :: Undefined Reference With Mingw (template Usage)

Apr 10, 2014

I am wondering why ToStr throws me this error. I am using mingw64 and codeblocks.

Code:

E:JackyDocumentsCode Blocks ProjectsPerfectSimXmain.cpp|35|undefined reference to `std::string ToStr<int>(int const&)'|

Code:
for (int i = 0; i < NO_CAMS; i++) {
std::string filename("E:/Jacky/Documents/Code Blocks Projects/PerfectSimX/Data/Cam");
std::string restFileName(".cam");
filename += ToStr(i);

[Code] ....

View 4 Replies View Related

C++ :: String Stream Usage To Parse The Line

Oct 7, 2012

I am working on a project were I have to read line form ( PLC ) programmable logic controller generated text file with lines like this

Circuit Value Current 2.33 4.32 5.55
there could be up to 3000 lines per txt file

I am using string stream to parse the line, for the sake of good programming I which to check weather first three values are string and last three values are actually floats raise or throw an exception if they are not ....

View 4 Replies View Related

Visual C++ :: MFC Proper Usage Of Sending Message To Dialog To Activate

Jan 7, 2015

I have finally got around to developing C++ & MFC using Visual Studio 2012, to build a full GUI Windows application (not sure if I have made the right choice). Though admittedly in two months time I do have a dialog window at my beck and call.

Now I have discovered a flaw (suspect) partially caused by the design of this program not all following the same principles, nor written by the same people and long predates me. Let describe the situation.

I have a dialog I have created as a class which has a combo box. The list of items are populate during the OnInitDialog() function just fine, except if the file where the detail is not yet read from that combo box would not have any items other than the default. This is to be expected in the use of the program, so fine.

However, if the dialog (modeless) was already open and active, when the user went up to and selected the menu command (main window) to read that file that CPtrList data structure that held that data would not populate that Combo box on my dialog.

So what I would like when I am done reading the files contents is to detect if my dialog is opened and if so send it a message to Activate (force a call to OnActivate()). I have gone to the event list for the dialog and exposed this event handler from the resource editor just fine.

I see the syntax of OnActivate() is

void MyClass::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimalized);

So nState is an Unsigned Int of the current state of the thread/window (not sure)?

CWnd* pWndOther is the CWnd of my other Window that wants my dialog to activate I think which is the main application since it was on the a menu that this function was called to read the file.

bMinimalized is whether my dialog is mimalized(?)

View 10 Replies View Related

C++ :: Colon Usage (single And Double) Member Initializer List?

Aug 27, 2013

The below code is taken from the open source 7zip project (7z920CPP7zipUIFileManagerBrowseDialog.h)

Code:
class CBrowseDialog: public NWindows::NControl::CModalDialog {

What does the single colon (CBrowseDialog:) mean? Is that Initializer List?

I know the double colon (NWindows::NControl::CModalDialog) is Scope Resolution Operator.

Why is (: public NWindows::NControl::CModalDialog) used with the class declaration?

Similar code is found through out the project along with class declarations.

View 2 Replies View Related

C++ :: Demonstrate Usage Of Each Member Function Using Test Data (width And Height)

Feb 11, 2013

Provide the definitions for the following class declaration and then write a program that demonstrates usage of each member function using the test data of 10 for width and 8 for height. Remember to put your main program, class header and class source into separate files. This is an easier version of the exercise than the one you have been asked to practice. Only provide code for the methods specified in the class declaration. Note that the displayRectangle() method should output an appropriate ‘box’, its dimensions, area and perimeter to the screen.

class Rectangle {
public:
Rectangle(int height, int width);
~Rectangle(void);

[Code] .....

View 1 Replies View Related

Visual C++ :: How To Reduce High CPU Usage Caused By Receiver Thread Of CAN Messages

Feb 13, 2013

I am writing a program which handles the CAN messages Received from BUS.My code is taking almost 60% of CPU usage.

View 14 Replies View Related

C++ :: Pointer Usage To Base Class Object In Vector Int Main Function

Aug 12, 2013

I know what are pointer's and how to use them but there is one point i am not able to understand. Below is the example code

I understand everything in the below code except 1 thing why i am using pointer to base class object in vector int the main() Function?

Code:
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
// base class

[Code] ...

Here is the lines of code i want to understand.

Code:
vector<Employee*> employees;
employees.push_back(&emp1);
employees.push_back(&mgr1);

I know if i will not use the pointer base class function "virtual double grossPay" will be called for both base class object and derived class object and when i will use pointer with reference to the object because base class function is virtual it will look for same function in derived class and if available it will execute it.

View 3 Replies View Related

C :: Can't Get Tic-tac-toe Win Algorithm To Work

Apr 9, 2014

I am writing a simple console-based tic-tac-toe game. I am trying to write a function to check whether someone has won the game.

The board data is saved in an array called board: Code: int board[3][3] with each element corresponding either to an empty spot, an X, or an O, using the numbers 0, 1, and 2, respectively. For clarity:

Code:
#define EMPTY 0
#define X 1
#define O 2 Here is my function: Code: int check_state(int board[3][3]) {
int winner = 0;

[Code].....

View 1 Replies View Related

C++ :: Algorithm For All Possible Combinations?

Mar 7, 2013

A few days ago I got a "bright idea" to see if I could match a string, with an arbitrary length from 1 to 12, to its formulated sequence by using an algorithm to find all possible combinations of the integer combinations from 0 to 9 at each length (1 to 12).

Example: Desired numerical combinations from integers 1 to 3:

At Length 1:

1, 2, 3

At Length 2:

11, 12, 13, 21, 22, 23, 31, 32, 33

At Length 3:

111, 112, 113, 121, 122, 123, 131, 132, 133, 211, 212, 213, 221, 222, 223, 231, 232, 233, 311, 312, 313, 321, 322, 323, 331, 332, 333

And so on until the nth length (in my case a length of 12).

First off, I would like to say that this is not as easy as I thought. I clearly underestimated the problem seeing as I've spent hours attempting to write a working algorithm, but feel like I've made no progress.

Here are a few of my attempts:

Attempt 1:

#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>

[Code]....

I can't exactly explain this one. It works if the length is 2 or less; however, the order of the output is horrendous.

Attempt 3: I tried using recursion, but only found myself getting more and more lost the further I tried developing my function. Cannot find my work for this attempt.

I would really like to figure this out on my own, but I am very stuck as you can see. I also lack time that I can spend working on this since im a full time student.

View 14 Replies View Related

C++ :: Extending STL Algorithm

Jul 24, 2013

I wrote a version of find_all() which searches through containers for matches and returns another container that holds iterators pointing to each match. When I compared what I wrote to what the authors of Professional C++ wrote, I found the two find_all() functions to be very different.Here they are:

//Mine
template<typename Iterator, typename Predicate>
std::list<Iterator> find_all
(Iterator front, Iterator back, const Predicate& match) {
std::list<Iterator> toreturn;
for(; front != back; ++front) if(*front == match) toreturn.push_back(front);

[code]...

View 5 Replies View Related

C++ :: VRP Algorithm - Run EXE In Website

Jun 27, 2014

I have VRP algorithm written in C++, run with command prompt Windows. input (command line) -> VRP.exe -> output (txt file)

Now I want to built a website to run it as SaaS. How to run an exe application(compiled c++) in server used as Saas? What kind of programming do I have to use? Ruby or html5 or others? I don't know how to start.

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved