|
I fixed the problem with the buffer index. Now I can notice three behaviors:
the first one, always producing one stuff and consuming it (in this case, I get a memory leak)
Produce: 1
Consume: 1
Produce: 1
Consume: 1
Produce: 1
Consume: 1
Produce: 1
Consume: 1
Produce: 1
Consume: 1
Produce: 1
Consume: 1
Produce: 1
Consume: 1
Produce: 1
Consume: 1
possibly lost: 272 bytes in 1 blocks
for the second behavior, I produced and consumed ten stuffs (and I got a bigger memory leak)
Produce: 1
Produce: 2
Produce: 3
Produce: 4
Produce: 5
Produce: 6
Produce: 7
Produce: 8
Produce: 9
Produce: 10
Consume: 10
Consume: 9
Consume: 8
Consume: 7
Consume: 6
Consume: 5
Consume: 4
Consume: 3
Consume: 2
Consume: 1
Produce: 1
still reachable: 1,552 bytes in 4 blocks
for the last behavior, everything went fine (without memory leaks)
Produce: 1
Produce: 2
Produce: 3
Produce: 4
Produce: 5
Produce: 6
Produce: 7
Produce: 8
Produce: 9
Produce: 10
Consume: 10
Consume: 9
Consume: 8
Consume: 7
Consume: 6
Consume: 5
Consume: 4
Consume: 3
Consume: 2
Consume: 1
Produce: 1
All heap blocks were freed -- no leaks are possible
|
|
|
|
|
I don't really see how your code can leak more than one block of memory when the entire program only allocates one!? Those leaks must be elsewhere - if those leak messages are indeed correct.
I suspect that the pthread library internally uses some kind of memory pool that doesn't get freed before the end of the program. I've seen the same thing in a CAD library that produces tens of thousands of "leak" messages because of that. It's very annoying becasue that way it's extremely difficult to pinpoint actual leaks, or find out if there even is one.
|
|
|
|
|
I see. Are those internal leaks a bad thing for a bigger program?
|
|
|
|
|
Well, if my assumption is correct, technically these aren't leaks - they just appear as such because memory pools are designed that way. If used correctly, these 'leaks' will not be a problem, except when it comes to the problem of locating real leaks.
Memory pools are used as a faster way to allocate and free lots of small blocks of memory. Basically they take up the role of a memory manager for specific types (or sizes) of objects. They may be capable of freeing unused blocks at runtime (reducing the number of "leak" messages), but doing so complicates the management effort considerably. As a consequence, most implementations never free blocks at runtime, they only grow when running out of free memory within already allocated blocks. That means the total cost of memory is the maximum load at runtime.
|
|
|
|
|
Just in case someone wonders, it was written in the book Programming with POSIX threads (the book I mentioned earlier), that we don't need to destroy (with pthread_mutex_destroy()) a mutex initialized statically i.e. with PTHREAD_MUTEX_INITIALIZER. Thank you people for all the attention given to this topic
|
|
|
|
|
I did follow this discussion which started badly – no real info was provided on the initial post, almost got into personal fist fight - “nobody spoon-fed me knowledge about programming” and ended up with no real solution to learn from.
I often wonder why people waste their time posting stuff like this.
… off my soapbox now...
|
|
|
|
|
I plan to develop a new application with Visual C++ but I am wondering which library to use for the GUI design. I.e. MFC, QT.. and so forth.
MFC is a native MS library and sounds nice but rumors say that it has no future.
What are your thoughts?
Would you start a new application with MFC?
Thanks for your answers.
|
|
|
|
|
I use VC 6.0 MFC, but I am a retired (cheap) hobbyist. I like the doc/ view “feature”.
It was suppose to simplify the windows messaging, but it made it more complicated.
May "professionals" will say that MFC lets you build quick base UI for your application, but IMHO it is a shaky foundation to build onto, adding anything requiring more that friendly, quick user interface application is a challenge using MFC.
That is why, again in my opinion, you see mostly dialog based sample codes here.
The key is in detailed planning – what do you want your app to accomplish.
And as far as future of MFC – I see a continuing trend to abuse “object oriented” hiding of the actual process and “foundation” is just another name for “wrapper”.
In short – do not use MFC if you want true control of your code.
Cheers Vaclav
|
|
|
|
|
Vaclav_Sal wrote: “foundation” is just another name for “wrapper”
MWC = "Microsoft Wrapper Classes?"
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
No future.
GUI developmeng is no future, too.
Algorithm is king.
|
|
|
|
|
yu-jian wrote: GUI developmeng is no future
What? Complete and utter rubbish. The UI is now more important than it has ever been.
|
|
|
|
|
MFC is burdened with several decades of legacy, and full of bad designs and ugly interfaces. You won't notice a lot of it when designing a small GUI project, but for serious, long-lived work, it is most certainly not a good choice.
However, your choice depends a lot on the application you plan to build:
- If you want to build one for the MS App Store, you probably have to build it on the basis of WinRT, not MFC.
- If you want one that runs on Win7, WPF is a better, more modern library than MFC.
- If in the long (or short) run you don't want to restrict your application to just Windows, you need a platform-independend framework like QT.
|
|
|
|
|
I agree with you.
It is a painful thing to use the MFC develop a GUI product. I need to use the GDI+ to make many self-define controls. The C# is more convient than MFC.
|
|
|
|
|
I would develop the user interface in C# and try to put the logic in VC++ if at all it is a mandate.
You talk about Being HUMAN. I have it in my name
AnsHUMAN
|
|
|
|
|
What is your goal?
For cross platform, Qt is probably the most dominant library.
For just Windows, .NET is the most dominant, though the actual UI jumps around (forms, XAML, Silverlight, etc.)
I personally love C++ and MFC and write small apps in both because I'm an expert in both (and will hopefully retire soon with that being my legacy of expertise.) However, if you are starting out, unless you are specifically interested in embedded systems, driver or kernel level code, C++ is a poor choice. Based on my recent interview experiences, Java probably has more demand than any language (Android is a big part of this) with C#/.NET web services being a close second. I have found increased interest in Qt, though I'm not convinced the demand will last much more than another decade, if that.
(On the flip side, iPhone apps are written in Objective-C. How long will that last? Who knows?)
|
|
|
|
|
I have given up on integrating MFC with VFW and embarking on usage of DirectX to collect data from USB video cameras.
I have found other sample code ( using MFC and VFW) and it behaves exactly the same way as my attempt to make it work.
I suspect that the issue is with my current ( and latest XP ) driver.
Besides getting used to confusing terminology – DirectX, DirectShow I have run into my first problem while using the sample code posted elsewhere here.
There seems to be MS specific and also VS release specific header sal.h ( or later sal2.h).
I have downloaded latest Windows SDK and this file is not there.
The “problem“ I am facing is that the file / header is defined in several VS versions, but than it also depended on other headers, as usual.
<b>I guess my silly question is – can these language additions , such as sal.h, by MS be downloaded individually from reputable source and not as a part of say VS 2010? </b>
The MS description lacks the “download from here” options.
As “painful” as it is I have no issue with creating my own headers dependencies.
Any reasonable advise will be as always appreciated.
Cheers Vaclav
|
|
|
|
|
On my system with Visual Studio 2010 Express I found it in C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include. A quick search with Windows Explorer should do it for you.
Use the best guess
|
|
|
|
|
Thanks Richard,
I am currently dowloading VS2010.
Vaclav
|
|
|
|
|
As a side note, I would just say that you are making the right decision. VFW is a dead end these days and DirectShow is a better option. Microsoft Media Foundation[^] is actually the next generation, replacing DirectShow. It requires Windows Vista or newer, so if you have requirements that includes using Windows XP, don't go down that route yet .
Soren Madsen
"When you don't know what you're doing it's best to do it quickly" - Jase #DuckDynasty
|
|
|
|
|
Soren,
thanks for the note. I have been hearing this “dead VFW” since I first started asking about it.
My “standard” reply - “popular” OpenCV is based on VFW! The “problem” is that people are just cutting and pasting all of the VFW sample codes (posted here and elsewhere) and NOBODY really knows how it works as a real event driven Windows API! You can always find a”timer” or infinite “loop” somewhere in these samples – including in OpenCV basic code sample.
As soon as I get this “sal.h” in, I am off and running!
PS My last name is Sal!
Cheers Vaclav
PS How may developers are "building " for Vista? or ME? I'll wait for Windows 10.
|
|
|
|
|
Hi
I'm at my wit's end trying to access a user's Google contacts from my Visual Studio 2008 C++ desktop application. It's all set up with Google and I can run a php script online using Curl to get exactly what I need. So I thought I'd access that web page from my program using CInternetSession but then I can't get the redirected page after it's authorised. Then I thought I'd try intalling curl to use with VS but that's a nightmare. I might be able to use c# functions but I haven't learnt that yet, and am not sure how I can mix that with C++ (I think it can be done but my overall understanding of programming would make it very hard). Can anyone suggest what my best route would be?
Many thanks for your time
Greg Chapman
|
|
|
|
|
Hi,
I am working on a project in which I have created a property sheet, I am using 3 property pages in that. Now it happens that it perfectly displays in Windows xp (72 DPI default ), but if I run it on higher DPI than 72 DPI, controls starts disturbing. Many of the controls will hide.
I have one list control and 3 buttons on that which I have created manually (Hard-coded), not created on any dialog. I am facing big problem in setting the position of that List Control and 3 buttons.
Please let me know if anyone have any suggestions about this.
Any help will be appreciated.
Regards,
Mbatra
|
|
|
|
|
Unfortunately the only answer is to create your own layout manager, that checks the dimensions and DPI of the screen on start up, and adjusts each control to fit.
Use the best guess
|
|
|
|
|
I'm trying to display an image from a stream data.
But there is no image when getting image::from stream.
It's my source code:
IStream* pstream = NULL;
if(SUCCEEDED(CreateStreamOnHGlobal(NULL, TRUE, &pstream)))
{
ULONG lreal = 0;
pstream->Write(chIncomingDataBuffer, iEnd, &lreal );
if(pstream!= NULL)
{
MessageBox(hWnd,
" Stream is OK",
"Connection strt",
MB_ICONINFORMATION|MB_OK);
}
Image* image =Image::FromStream(pstream);
if(image)
{
RECT rect;
::GetWindowRect(hWnd, &rect);
Graphics graphics(hWnd);
graphics.DrawImage(image, 0, 0, rect.right-rect.left, rect.bottom-rect.top);
}
else
{
MessageBox(hWnd,
"No image is written",
"Connection strt",
MB_ICONINFORMATION|MB_OK);
}
if(image)
delete image;
image = NULL;
if(pstream)
pstream->Release();
pstream = NULL;
}
There is no image from data. Can anyone help me in this?
Thanks!
|
|
|
|
|
I have never tried doing it this way, but it looks like you took the sample from here[^], removed some stuff to make it simpler and changed it to write directly to your generic IStream object. I am not sure I like the whole thing, but it is kind of an interesting approach - if it works.
You do not show how you acquire the data that is stored in chIncomingDataBuffer . Are you sure this buffer contains an entire image?
I don't know if it is going to work, but right after you write the data to your pstream , its internal position will be pointing to the end of the data you just wrote. Try calling Seek() in order to change it to point to the start of the data.
Soren Madsen
"When you don't know what you're doing it's best to do it quickly" - Jase #DuckDynasty
|
|
|
|