|
Thanks Mark,
somehow I knew that simple loops won't work.
Vaclav
|
|
|
|
|
You can use a single loop as long as the values of any possible row
padding bytes doesn't affect your math, but you still have to know
the extra bytes may be there.
Also, biSizeImage is allowed to be 0 - you need to check for that and calculate
the value if it is:
if (0 == biSizeImage)
biSizeImage = stride * abs(biHeight);
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark , thanks for the addendum.
But I spoke too soon. My code still asserts. My bitmaps size is 320 wide and 240 high and it asserts in about half height. I must have screwed up something. It looks like I do not have 24 bit biBitCount.
But right now I have another pressing issue ( babysitting my new grandson!)so this one is temporary on hold. Here is my code in case you want a good laugh.
As always "->" are = -> !
I do not understand why this editor does that to my code! Tired of "fixing it"!
PS. It seems to make no difference if I use casts as you suggested.
RGBQUAD *CurrentRow;
//lpBi->bmiHeader.biBitCount = 32;
LONG stride = (((lpBi->bmiHeader.biWidth * (long)lpBi->bmiHeader.biBitCount + 31L) & (~31L)) / 8L);
if(lpBi->bmiHeader.biBitCount == 24)
CurrentRow = lpBi->bmiColors; // 24bpp pixel data - use RGBQUAD
else
{
//AfxMessageBox("Unsuported bitmap format");
}
CurrentRow = lpBi->bmiColors;
for (int y = 0; y < lpBi->bmiHeader.biHeight; ++y)
{
for (int x = 0; x < lpBi->bmiHeader.biWidth; ++x)
{
iRed = CurrentRow[x].rgbRed;
iGreen = CurrentRow[x].rgbGreen;
iBlue = CurrentRow[x].rgbBlue;
/*
histogram[RED][iRed] += 1;
histogram[GREEN][iGreen] += 1;
histogram[BLUE][iBlue] += 1;
*/
icount++;
}
CurrentRow += stride;
}
|
|
|
|
|
Change
CurrentRow += stride; to
CurrentRow = (RGBQUAD *)((BYTE *)CurrentRow + stride); I changed that in my original reply code
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi there,
I'm really stumped with the memory re-allocation with a CListCtrl in MFC after using the SetItemData function
and was wondering if any of you could help me out.
Here goes:
I have a class MyClassX which I instantiate using MyClassX * myClassInst = new MyClassX();
I add this instance to a CListCtrl myListCtrl using the following: myListCtrl.SetItemData( lineX, (DWORD)myClassInst );
This is all well and fine and I am able to retrieve the data and work with it, all happiness, however here is my problem.
When the time comes to delete this class, I step through each entry in the list pulling out its data item with
MyClassX * tmpClassX = (MyClassX*)myListCtrl.GetItemData(index);) and subsequently call delete tmpClassX; which deletes the instance no problem.... however, closer examination on the memory tells me otherwise. Even though the destructor of the MyClassX was called, and the instance no longer exists, the memory allocated for the class does not free.
I've tested the deletion process without adding the class to the CListCtrl and my memory is always reclaimed, however once adding the data to the list, the memory is never freed. (After first physically deleting the created classes, then calling DeleteAllItems on the list).
This is very puzzling to me and I'm beginning to wonder if some malloc operation goes on inside the CListCtrl once the SetItemData is called, but the memory is never de-allocated once cleared.
Should I create a "light weight" struct with a (void *) pointer and an index and just add this struct to the list rather?
Should I override the DeleteAllItems call in a custom list?
I’m absolutely puzzled!!
Thanks in advance...
|
|
|
|
|
Psyinx wrote: ...the memory allocated for the class does not free.
How are you verifying this?
Psyinx wrote: ...I'm beginning to wonder if some malloc operation goes on inside the CListCtrl once the SetItemData is called, but the memory is never de-allocated once cleared.
How would the list control know that you've deleted the memory pointed to by the call to GetItemData() ?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
DavidCrow wrote: How are you verifying this?
Simple: The application that is using the list revolves around an extreme amount of incoming data. After the usual steps of creating the structure that will be used inside the list, instead of adding it to the list, i delete it, using the same deletion code i use upon clearing the list.
Watching the applications memory usage with the list added data, the memory can grow from 30mb to 150 within a matter of 5 minutes.
Without adding the data to the list, the application remains constant at 30mb.
I've made 100% sure that after adding the classes to the list that my garbage collection is done once the list is cleared
(for every constructor called i increment a counter, for every destructor called i decrement the counter, and lo and behold, it
shoots to 2000 at max (my ceiling for the list), then back down to 0 once their destructors are called.)
I know for a fact that the destructor code is cleaning up the object as without the list, the memory is constant.
DavidCrow wrote: How would the list control know that you've deleted the memory pointed to by the call to GetItemData()?
This is a good question.. However once the object has been deleted, it should automatically reclaim the memory from that object that has been deleted.. or at least this is what should happen in theory (and does happen without the call to SetItemData), also what confuses me is that i'm handing the SetItemData a pointer, and not the actual "data", and the last time i checked, 2000 pointers do not add up to 120mb..
I'm definitely missing something here! Am i assigning the data incorrectly? Deleting the data incorrectly? Clearing the list incorrectly? I'm really stumped!
Is there a message that i can send the list to inform the list that the data has been deleted?
Thanks.
|
|
|
|
|
Psyinx wrote: Watching the applications memory usage...
Using?
Psyinx wrote: However once the object has been deleted, it should automatically reclaim the memory from that object that has been deleted...
That is not the way Windows' memory manager works.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi, I am having the same problem. Doesn't seem that the memory is re-claimed...
So how does Windows' memory manager work? Sorry, I'm still a n00b, but I am confused as to why this happens.
|
|
|
|
|
bonkers123 wrote: Doesn't seem that the memory is re-claimed...
How are you verifying this?
bonkers123 wrote: So how does Windows' memory manager work?
It's extremely complicated, and I only know bits and pieces of it.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I'm using perfmon and Process explorer.
You mind sharing the bits and pieces you do know? It may be of some help.
Tnx.
|
|
|
|
|
bonkers123 wrote: You mind sharing the bits and pieces you do know?
A lot of folks erroneously use Task Manager to determine if their code is "leaking" memory.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I know that's one of the biggest mistakes a person can make...
Anyway... problem seems to be sorted. Tnx, I Geuss....
|
|
|
|
|
Hi,
I have a two part question, can be written in either C++ or C#
1. How to figure out which versions of VC++ runtime installed on the computer?
2. How do I write a bootsrap program that checks if Visual C++ 2008 Libraries installed or not and then goes and install Visual C++ 2008 Redistributable Package if not installed?
Thanks
Ben
|
|
|
|
|
ben2 wrote: 1. How to figure out which versions of VC++ runtime installed on the computer?
It well built in with VC++ redistributable package!, if the VC++ redistributable is installed on the computer, then installer will do nothing!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You/xml>
|
|
|
|
|
I searched the forum for this specific question and can't find it so here it is.
I ran into this "extern inline" syntax in several U-boot C header files. I know the idea about putting extern is to avoid the multiple definition, but the confusing part is the inline part.
What happens in my compiler is this... it takes the extern, but not the inline. So during linking, it's looking for that function, and can't find it.
Now I normally use inline keyword for C++ header files that is protected by include guard, so the extern is not really useful (especially inlined functions already have definition there).
My question is, can someone explain in layman's term how this "extern inline" supposed to work?
They seem to be mutually exclusive to me: "extern" keyword means "it's defined somewhere else" and inline means "replace your code with this definition".
So I believe my compiler is behaving correctly...
Yes, I know I can google into this, but I'm just too lazy to think now
Thanks!
|
|
|
|
|
If the function can be inlined it will be, otherwise it will attempt to link to the function. This means it must exist in source somewhere. One thing to check is if a macro is used to define "extern inline" and can be turned on/off easily.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
|
my application is dialog based MFC appln. VC 6.0
please help me ASAP.
Thanks
RAM
|
|
|
|
|
Have you considered CDC::SetBkColor() ?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi
I am looking for C program source code. Could you please help me in finding the source code of the required mentioned below.
Task that I need to complete:
Write a program to create multiple threads (one master thread and rest worker threads) and using the threads write into and read from shared memory.
Restrictions:
Only one thread should be able to read at any instant of time into shared memory region.
Only one thread should be able to write at any instant of time into shared memory region.
Worker threads should inform the master thread after every read and write operation.
Master thread inform the worker thread (which is waiting to acquire shared memory region) that read or write operation is successful and it can acquire the memory for either reading and writing operations.
|
|
|
|
|
You can use a mutex to limit access to shared memory to only one thread. You'll have to write the code yourself; that's the point of taking a class.
|
|
|
|
|
Subhankar wrote: Could you please help me in finding the source code...
Isn't the main purpose of your class to create the code rather than find it?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
What an excellent question! This is a LOT more clearerer than Globule Beats Brick! Here you go, you can write the void main() function:
char data[360];
class rthread {
char* myDataPtr;
rthread(char* ptr){
myDataPtr=ptr;
}
bool write(char* d,int size){
return memcpy(d,myDataPtr,(size>360?359:size));
}
}
class wthread {
char* myDataPtr;
wthread(char* ptr){
myDataPtr=ptr;
}
bool read(char* d, int size){
return memcpy(myDataPtr,d,(size>360?359:size));
}
}
class mthread {
char* myDataPtr;
wthread* myWriter;
rthread* myReader;
mthread(char* ptr){
myDataPtr = ptr;
wthread = new wthread(myDataPtr);
rthread = new rthread(myDataPtr);
}
~mthread(){
delete wthread;
delete rthread;
}
bool read(char* c,int size){
return myReader->read(c,size);
}
bool write(char* c,int size){
return myWriter->write(c,size);
}
}
|
|
|
|
|
I am a beginner and I really don't have any idea about C++. I really in need of C code.
|
|
|
|