I have an application that randomly displays images on a screen. There's a capture button, and when user clicks on that button, the image that is currently displayed is stored into a buffer.
User can click the button 5 times. i.e., the buffer should be storing upto 5 image data.
I have code like this,
unsigned char* m_ImageBuffer;
m_ImageBuffer[counter] = new unsigned char[size];
memcpy(m_ImageBuffer[counter], pImageData, size);
The variable "counter" goes from 0 to 4. Inside the WHILE loop a bunch of images are constantly displayed
in the screen.
The purpose of m_ImageBuffer is that, i will store the user selected image data in this buffer, so that it could be later used for display. i.e., in a different screen.
The problem with the code in WHILE loop is that, i am not able to use DELETE properly. So the code logic basically ends up eating so much memory.
I am looking for a better logic, by which i can store the image data, but still does better memory management.
Not sure the problem is explained properly. I am expecting some suggestions on how to manage this situation.
Apart from the solution that Richard has given, I'd like to suggest you to go through the code snippet from WHILE block and ensure that the array index variable 'counter' is increased properly whenever an image is selected. Because, looking at the code snippet you gave, the index variable 'counter' is not incremented immediately after allocation index element (or you didn't include that part while pasting the code).
Looking at the logic you explained, it seems that you may not be deleting the image data in the while loop. Or are you?
If the user has the choice of deselecting the image, you should be able to delete the respective indexed image item, and should maintain the empty slot index data. That involves extra bookkeeping.
I would suggest to give a try using STL container classes. For that, this[^][^] may help you.
If possible, provide the full WHILE loop code snippet. That will help to find out memory leak (as your app is ending up much memory).
<pre><pre lang="text"> I can specify relative path from current directory using “Additional include directories “ to a directory on same level and it compiles. Same method works when “going up” in directory tree.
Additional include directories ( for compiler ) .\TESTLib #include "..\_TEST.h" #include "..\StdAfx.h" Now how do I specify the path to a subdirectory? My directory “Modules” is on same level as project directory and “DIrectShow 8.1 SDK” is its subdirectory.
This does not work, obviously I am missing something.
Additional include directories .\Modules\DIrectShow 8.1 SDK #include "..\Modules\DIrectShow 8.1 SDK\_TEST_B.h" Any help or reference source / sample would be greatly appreciated. Cheers Vaclav </pre></pre>
Yes, that works, I used it for test, but I need to specify common path for the rest of the includes. That is why it is in " Addtional include " settings. The "problem " is I do not know how to access directories not in direct "up" path from the main (project) directory. And to be honest, I kinda forgot how to do "system" variables. I guess I need to brush up on DOS.
Additional include directories
.\Modules\DIrectShow 8.1 SDK
#include "..\Modules\DIrectShow 8.1 SDK\_TEST_B.h"
Do you see why that makes no sense? You have told the compiler to look in .\Modules\DIrectShow 8.1 SDK, that is to say, two subdirectories below the current one. You then give a different path in your #include statement, which says that the Modules directory is a sibling of the current one. If you add the paths in your project settings then you don't need to add them in your #include statements.
I need this path because there are other includes in streams.h In my foolish way of thinking - I need to go up two levels to common 00 Video directory and than down 5 levels. I relatively know how to "go down ..\" but have no clue how to "go up". Is that even possible?
If you take advantage of the Macros for Build Commands and Properties[^]; based on your two paths I think you would this to your 'Additional Include Directories' :
$(ProjectDir)\..\..\..\SDK\DirectShow 8.1 SDK\samples\Multimedia\DirectShow\BaseClasses\
Note that $(SolutionDir) is the path to the solution file (*.SLN) and $(ProjectDir) is the path to the project file (*.vcproj || *.vcxproj)
David, I have been looking at compiler "include option - /I ". There is something about putting a "base" directory in the option string. Pretty much in same line of though as you suggested. I'll play with that.
Richard, as far as putting the absolute path in this option string there is a minor but important issue in reusing the project as a "module" in another, main , project. Right now I finally got my main project working and it consists of several such modules. I prefer to build the module separately, it is less confusing.
You seem to be making things more difficult for yourself than necessary. Using relative paths in situations like this can cause problems if any part of the path gets moved or renamed. Just add the full absolute paths of all required directories into your project's properties file and then you don't need to specify any part of them in your #include directives. So in this case add both of the following to your project:
I have changed my directory structure and separated the common "applications" from the project. That way each project can access the common application, likes SDK for example, using direct path. Thanks for all suggestions, it helped to reinforce the KISS motto.
I am a starter to UI Automation and I see there is no good example or document to read about UI Automation in C++.Any one please help me with some code snippnets to start wrkng with UI Automation in "C++" Thanks in Advance. Regards, Amrut