|
Hi
I have two questions on C++:
1. If my application continuously allocate and relase memory (each allocation is around 40Kb, and there may be around 40 allocations and deallocations on each iteration), will the application run faster if I were to write a memory manager class that, instead of freeing the allocated memory, it stores it in e.g. a linked list and reuse it when the app requests for memory?
2. If using a memory manager class will be faster, how can I share an instance of this class among all the classes that needs it? I think it will be more efficient to just create one memory manager instance and share it among all the classes, instead of creating one instance of the memory manager for each class that needs it.
Thanks!
|
|
|
|
|
Indrawati wrote:
will the application run faster if I were to write a memory manager class
This is a great post!
In Win32 this would only be true if you think you can improve upon the systems memory manager.
By default, the Process heap performs coalescing operations. (Coalescing is the act of combining adjacent free blocks to build a larger block.) Coalescing costs additional cycles but reduces internal fragmentation of heap blocks.
From: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dngenlib/html/heap3.asp[^]
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
In my current project we have a "large" code base of about 100K SLOC and a set of unit test code of about 50K SLOC. Our challenge now is to maintain the correlation between the test code and the project code. Most of the test code specifically tests a single class/method.
I'm looking for a way to:
1) Quickly determine for a project class/method which test code covers it and vice-versa.
2) Using the above detect where there are "holes" in our testing.
Several options we have considered are:
A) Maintaining an external to the source code reference (spreadsheet, etc.) - This is difficult since it is a separate cross reference to maintain.
B) Documenting directly in our comments using DOxygen's \test tag the relation from project to test code - here, if we document in the project code, a change to the test code would make us change the comments in the project code.
C) Continue attempting to use a code coverage tool like DevPartner Studio's TrueCoverage to generate this data. Unfortunately TrueCoverage's output format doesn't seem conducive to this type of reporting. For example, it doesn't distinguish overloaded methods.
Any tools, procedures, and options are appreciated.
|
|
|
|
|
I need to stay focus on a dialog I dont want to leave focus from the dialog how do I do that?
|
|
|
|
|
Is a modal dialog out of the question?
KMaz?
|
|
|
|
|
ok, But how can I make so you cant press "ESC" or anything to exit the dialog?.
I Want to use a button to exit the dialog not press ESC or anything else how do I do This?
|
|
|
|
|
Override the OnOK and OnCancel functions to do nothing
KMaz
|
|
|
|
|
Ok but you can still press the ESC button to exit the app.
|
|
|
|
|
If you overload the OnCancel function you cant escape via the escape button....the alternate solution is a keyboard accelerator, but its more difficult to impliment
-Kmaz
|
|
|
|
|
|
use the function setwindowforground
-----------------------------
"I Think It will Work"
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
Does anyone have any ideas on how to make a dialog box be only draggable within its parents window...ie....if someone tried to drag the dialog passed the borders of the main application, it wouldnt let them. im trying to go for a toolbox type style....thanks.
KMaz
|
|
|
|
|
Hi there.
Does anyone know how to treat a command line argument as a single argument, instead of the default mechanism of providing space delimited tokens, as in the standard argn/v implementation.
James.
|
|
|
|
|
How about the GetCommandLine() API call?
|
|
|
|
|
Thanks.
Will check that out.
James
|
|
|
|
|
I have read a few of the dll tutorials on this site, but I'm still having a problem. I have a dll that does a global hook that I would like to use to reroute the message to another application. I also have a PreTranslateMessage function overridden in my Ceditview class that works fine with its MSG* parameter. Most of the examples I've seen use the user-defined messages to reroute the messages to a user's app, I'd like to reroute the entire message.
If it's broken, I probably did it
bdiamond
|
|
|
|
|
Hello i have standart MDI aplication generated by AppWizard and my task is to draw someting(bitmap) on main frame window. Something must be visible (a logo) on a frame window (in this gray area) when there aren't opened any views or views aren't maximazed. I will be greatefull for any help.
|
|
|
|
|
Hi All,
I use the code below to load a bitmap file to my program.
void CStartupDlg::LoadPictureFile(HDC hdc, LPCTSTR szFile, CBitmap *pBitmap, CSize &mSize)
{
// open file
HANDLE hFile = CreateFile(szFile, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
_ASSERTE(INVALID_HANDLE_VALUE != hFile);
// get file size
DWORD dwFileSize = GetFileSize(hFile, NULL);
_ASSERTE(-1 != dwFileSize);
LPVOID pvData = NULL;
// alloc memory based on file size
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwFileSize);
_ASSERTE(NULL != hGlobal);
pvData = GlobalLock(hGlobal);
_ASSERTE(NULL != pvData);
DWORD dwBytesRead = 0;
// read file and store in global memory
BOOL bRead = ReadFile(hFile, pvData, dwFileSize, &dwBytesRead, NULL);
_ASSERTE(FALSE != bRead);
GlobalUnlock(hGlobal);
CloseHandle(hFile);
// create IStream* from global memory
LPSTREAM pstm;
HRESULT hr = CreateStreamOnHGlobal(hGlobal, TRUE, &pstm);
_ASSERTE(SUCCEEDED(hr) && pstm);
// Create IPicture from image file
hr = ::OleLoadPicture(pstm, dwFileSize, FALSE, IID_IPicture, (LPVOID *)&gpPicture); <==== It said the memory allocated here is not released.
_ASSERTE(SUCCEEDED(hr) && gpPicture);
pstm->Release();
...........................................................................
gpPicture->Release();
}
After I use "Rational Purify" to check memory leak, it reports a memory leak happened.
Could you tell me what I shd release?
Thanks in advance
Vincent
|
|
|
|
|
vincentye wrote:
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwFileSize);
Where is the matching call to GlobalFree() ? See here for an example that complements the Loadpic.exe example from MSDN. Here is a class example.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Thx for your reply.
I did try GlobalFree(hGlobal), follow the code of "pstm->Release()", but Purity told me I am trying to release an unallocated memory. Where shd I put the GlobalFree() function in this case? If I put it before pstm->Release(), Purify told me this message : "[W] PAR: Global/LocalLock(0x571001c) arg #1 (hMem) attempt to lock handle that is on pending free queue. {1 occurrence}"
Thx again
Vincent
|
|
|
|
|
Hi.. I'm total new to GDI+
I dont' even know what it is exactly yet. Before I go seeking more information to find out whether I can use GDI+ to get the images (jpg, tiff, gif) properties, I think I better ask gurus first so if it is not the right one for me, I wont' waste my time reading and searching more information to find out GDI+ can solve my problem.
Could I use GDI+ to get the images (tiff, jpg, or gif) information such as, resolution, image size, color/ black and white etc ?
If GDI+ is the right class to use it. How to use it please.
Thank You
|
|
|
|
|
Hello,
I have RGB data of a bitmap in a buffer. And i want to get a HBitmap from this data so that i can select it in MEmory and then blit it to screen. Can anyone help???
Omar Alvi
|
|
|
|
|
First, a simple question: do you have any other method of transfering the bitmap data, other than raw RGB ? Such as a bitmap file ? Creating bitmaps from raw data is a painful process, and very sensitive to errors..
But, let's get to it. The following check-up list will create somekind of a bitmap for you and blit it to the screen. It might or might not look correct.
1. Create a memory device context that is compatible with the display or the window you wish to blit to.
2. Create a bitmap that is compatible with this DC, specifying the width and height as you do. The width and height are dependant on the size of the color data you have. They MUST match.
3. Select the bitmap into the device context.
4. By using SetPixel , set the color of each pixel in the memory DC. You get the colors from the data at the buffer.
5. Blit from the memory device context into the target DC.
After this, the target DC contains a representation of the bitmap data in memory. The colors may be wrong, and if so, you need to determine the palette that was first used to create the data in the memory. This is next to an impossible task (probably), so I can't advise you further in that.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Amm well actually i guess i dont have any other method of trasfering bitmap other than raw RGB.
Actually i have a bitmap lets say image.bmp file i can use LoadImage() to get the hBitmap handle to it which can then easily selected in memory and then blitted to screen...
But the problem is that i want to read an encrypted bmp file(whcih i encrypt myself) and then decrypt it and afterwards i want to display it in GDI so i need to get the hBitmap handle....i guess the only way is to make the bitmap from raw rgb data..any bright ideas ???
Omar Alvi
|
|
|
|
|
If this is the case, then you should divide your process into a two-fold part: the first part consists of the encryption/decryption methods. Both of these functions work on plain files only.
An example: you have a non-encrypted bitmap file. You then give this file's name into the encryption function, that uses the algorithm you determine to write a NEW file, that contains encrypted data. Now, you have an encrypted file.
Next you can give this file as an input parameter to the decryption method, that decrypts the file and WRITES the non-encrypted bitmap file to disk again. When the file write is complete, you can give the file name as a parameter to LoadImage that will then load the bitmap image from disk into memory and give you a HBITMAP handle to it. When the loading is complete, you can delete the non-encrypted bitmap file, leaving only the encrypted one to the disk.
Last alternative is to create the bitmap from scratch. Doing it requires you to fill BITMAPV5HEADER , BITMAPINFO structures, then call CreateDIBitmap to create a device-independent bitmap. An alternative way is to use CreateDIBSection, which will create the DIB and give you a pointer to the location of the DIB bits. You can then use the pointer to write the DIB data directly.
There seems to be one example available here on Code Project. See here.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|