I am using CByteArray as a buffer in Visual C++. I want to preallocate nSize memory for for CByteArray, so that later when I try to change the buffer, by calling SetSize, Add, Remove, etc., as long as all these operations are within nSize, CByteArray will not try to release the memory or reallocate the memory, so to eliminate the possibility of memory fragments in heap. Is that possible?
I have a JPEG in memory as a char* and a bytesize, if I save it to disk with a .jpg extension it's a perfect JPEG file. The thing is, I don't want to save it unless it's a minimum width/height. I got it into memory using a socket recv() call. What should I do ?
I am developing a Visual C++ application. There is an object called CMyObject, as follows:
typedef CMap<UINT, UINT, void *, void*> CMyMap; class CMyObject { public: CMyMap *m_pMyMap; "Some other member variables" }
Some instances of CMyObject contains a map, some not. Therefore, to save memory, I define a pointer m_pMyMap and create a new CMap object only if the instance contains a map.
When I test my app, with the increase of the CMyObject instance, the number of memory blocks allocated and deallocated is also increasing. There are a lot of fragments during this period. To prevent this, I try to override the new/delete operator for CMyObject and CMyMap. But still find many fragments. So I try to trace into the MFC source codes for CMap. I find CMap is just using an internal buffer to store the hash table(m_pHashTable), as follows:
m_pHashTable = new CAssoc* [nHashSize];
And for each hash entry, it uses:
P = (CPlex *)new BYTE[sizeof(CPlex) + nMax *cbElement];
To allocate the spaces.
I believe these two may be the reason of the memory fragments and want to eliminate them. However, is there a way to override the new/delete operator for codes such as:
new CAssoc* [nHashSize] and (CPlex *)new BYTE[sizeof(CPlex) + nMax *cbElement]
So that the spaces will be allocated from my own memory manager instead of from the default heap?
I get a memory leak error for every instance where a CString is set. I tried moving this to the MainFrame just to see if there was something with this being in the app, and saw the same memory leak errors.
I didn't include the functions in this class that manipulate this table. I didn't put it in the document because this is a multi-doc application and this table is universal to the program.
Is this an example of a false positive in the memory leak checker, or did I do something wrong?
when ending my app in the debugger, memory leaks will be shown like this:
Detected memory leaks!
Dumping objects -> C:PROGRAM FILESVISUAL STUDIOMyProjectsleaktestleaktest.cpp(20) : {18} normal block at 0x00780E80, 64 bytes long. Data: < > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD Object dump complete.
How can I tell Visual c++ also to show me the memory leaks in a called dll?
I have a MFC app that has a CDHtmlDialog embedded in it. During run time i update the HTML content from the C++ code. There's a IMAGE tag in the content and the SRC for the tag is updated multiple times in a second to show different images.
Basically i go over a WHILE loop in the C++ and call a JavaScript function to update the "src" for the "img" tag.
The issue am seeing is that, after running this code for a while the application kinda hangs and the system takes up lot's of memory.
How to solve this, as all the code that's in the browser side of app is HTML & JavaScript. I looked through the C++ code plugged all memory leaks there.
When running my code in Visual Studio, there is a particular point in the code where my program is crashing. To debug this, I am adding a break point in Debug mode just before that point, and observing what happens as I step through the code. However, to get to this break point in the code takes about a minute of running the program. So I'm wondering if there is a tool in Visual Studio to reload the state of a program's memory from a previous run, so that I can immediately get to the break point without having to wait for a minute each time?
I am getting "driver could not be loaded due to system error 8" error while connecting to SQL Server 2005 from VC++. Its also throwing out of memory error. Basically i am developing and ISAPI dll. I use the following code to connect to DB.
I am using new operator, I don't recall what the allocator's name is. But what is the corresponding Exception (or derived classes) any try-catch block can cope with?
I have CAN Dll program for my application,which was separately used.Now I have included the Drivers program into my application Program and I am having this error System Access Violation Exception:Attempted to read or write protected memory.i am attaching the Dll code and Application code which is throwing this error.
My Application Code which is the receiver thread for accessing the messages got onto the CAN bus.
DWORD WINAPI Rcv_Msg(LPVOID param){ int*MsgId = new int;//msg id from CAN intRcvVal;//0 = there is data in the queue; 1 = there is no data unsigned int uMsgId; *MsgId = 0; unsigned char CanData[8];
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>
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 );
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
We 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.
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.
I 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.
# 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 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.*/
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.