|
Thanks a lot.
But can you give me a example, or It's application?
|
|
|
|
|
It's very simple - say you're working in a very tight memory space (some kind of embedded system that doesn't have huge amounts of RAM)
On a normal PC, you'd probably just assign everything as ints
struct DATETIME
{
int nDay;
int nMonth;
int nYear;
int nHour;
int nMinute;
int nSecond;
}
making the assumption that each int is 32bits (4 bytes) then you'll see that each DATETIME will take 24 bytes of memory
Now, if you think about it, you don't need 32 bits for each of these variables
Day can be from 1 to 31 - so fits in 5 bits
Month can be from 1 to 12 - so fits in 4 bits
Year can be represented as 0..256 if you add on a year offset (and don't intend to use years in the far future or in the distant past) - so 8 bits
Hours: 0..23 - 5 bits
Minutes: 0..59 - 6 bits
Seconds: 0..59 - 6 bits
So if you total all those up (5+4+8+5+6+6) you get a total of 34 bits
struct NEWDATETIME
{
unsigned char nYear;
unsigned int nDay:5;
unsigned int nMonth:6;
unsigned int nHour:5;
unsigned int nMinute:6;
unsigned int nSecond:6;
}
The actual amount of memory used will vary depending on how inteligent the compiler is, but if it behaves correctly it'll use far less memory than the original struct (and if you've got thousands of these in memory, you'll see what a saving it'd be!)
--
Help me! I'm turning into a grapefruit!
Phoenix Paint - back from DPaint's ashes!
|
|
|
|
|
struct NEWDATETIME
{
unsigned char nYear; // 8 bits is all we need
unsigned int nDay:5;
unsigned int nMonth:6;
unsigned int nHour:5;
unsigned int nMinute:6;
unsigned int nSecond:6;
}
So the colon operator in the declaration above simply means nDay, nMonth... takes several bits instead of 30 bits for each of them. Other than that there's no any different with the former declaration which is every member element in the DATETIME structure takes 30 bits regarding the implementation and assignment? Just out of memory consumption thinking?
Am I right?
|
|
|
|
|
Yup - basically if you type unsigned int nDay; you're saying "I want an int called nDay" and the compiler will likely allocate 32 bits for it.
If you have unsigned int nDay:5; you're saying "I only need 5 bits for this variable" - whether the compiler allocates 5 bits, or gives you a full 32 bits is up to the compiler, but if it works properly it'll let you save memory.
So in other words, 9 times out of 10 you'll probably never use it.
In the example you gave, it looks like it's something to do with parsing the data in an MP3 file - this is quite a common use of bitfields, since it lets you quickly read in an abstract binary file into sensible variables
--
Help me! I'm turning into a grapefruit!
Phoenix Paint - back from DPaint's ashes!
|
|
|
|
|
Well, Thanks a lot.I really appreciate your patience!
Yes, I'm working on a MP3 file parsing!
And I'v got the example source code, but It seems hard to grasp!
|
|
|
|
|
See here.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
I am comparing two bitmap files, when a match has been found between two bitmaps, the matched portion should be highlighted by drawing a rectangle around it.
pls help with some coding
|
|
|
|
|
How can I get parameters (signature) of a function exported by a C DLL? I am looking for a tool or any code that achieves this. Dependency Walker fails to show signature of C functions, why?
ARSALAN MALIK
|
|
|
|
|
That is why you need the header files for the dll/lib.
onwards and upwards...
|
|
|
|
|
Can this be done without header file(s)?
ARSALAN MALIK
|
|
|
|
|
Hi all,
I have the following function in my VC6 project:
<br />
LPSTR getFieldName(int index)<br />
{<br />
return (index < 0 ? "abcd" : SysAllocString("Newstring")) ; <br />
}<br />
It runs well in VC6 if I give the preprocessor macro OLE2ANSI.
When I convert the same project to VS.Net 2003, It starts giving errors in atlconv.h. So I had to remove the OLE2ANSI macro from preprocessor definitions.
Then it give the error:
<br />
c:\src\INCLUDE\OIP.CPP(123) : error C2664<br />
: 'SysAllocString' : cannot convert parameter 1 from 'char *' to 'const OLECHAR*'<br />
It gives the same error in VC6 with out the OLE2ANSI macro.
Is there a macro in .Net that can be used instead of OLE2ANSI in VC6?
Any idea how to solve the issue?
thanks...
|
|
|
|
|
What you try to do man???
LPSTR getFieldName(int index)
{
return (index < 0 ? "abcd" : SysAllocString("Newstring")) ;
}
This is totally stranger code i suppose
SysAllocString - allocated BSTR - BSTR is OLECHAR* olechar is WCHAR or CHAR (depend on macro definition OLE2ANSI and system).If you wont to return just LPSTR why you don't do this
return (index < 0 ? "abcd" : "Newstring") ;
and in any way when you allocate string by SysAllocString you shoul remove one by calling SysFreeString but when you return some constant string you don't care about this at all.
|
|
|
|
|
I am converting a VC6 project to vs.Net 2003
This is some part of the code that works perfectly fine in vc6 and giving the error in vs.Net.
I don't want to change the code that is tested and working.
Why is the same code giving error in vs.Net?
Thanks a lot for your reply...
|
|
|
|
|
The issue is not solved, please help...
|
|
|
|
|
Hello,
Can I read function signature from a flat DLL without TLB or LIB extension? Actually, I can read function name but not its parameters from a DLL. What do you suggest about it? Thank you.
Regards,
Orkun GEDiK
SAP R/3 Software & System Support Specialist
ASTRON
|
|
|
|
|
Do u Able to see the Mangled name of Function .
if yes undname.exe to get actual parameter of function
-----------------------------
"I Think this Will Help"
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
I'm sorry but I can't see any name-mangling at "dumpbin" output at below;
Section contains the following exports for BtCePhilipsCF.dll
00000000 characteristics
3F873F3A time date stamp Sat Oct 11 02:22:34 2003
0.00 version
1 ordinal base
10 number of functions
10 number of names
ordinal hint RVA name
1 0 00001800 BTF_Close
2 1 00001708 BTF_Deinit
3 2 00001920 BTF_IOControl
4 3 000015D0 BTF_Init
5 4 0000178C BTF_Open
6 5 00001A10 BTF_PowerDown
7 6 00001A0C BTF_PowerUp
8 7 00001854 BTF_Read
9 8 00001918 BTF_Seek
10 9 000018B4 BTF_Write
Regards,
Orkun GEDiK
SAP R/3 Software & System Support Specialist
ASTRON
|
|
|
|
|
Actually i am too facing his type of problem and can't found any solution till now,nly soltion i know is that if you in nay case find mangled name you can get real function parameter using UNDName.exe.
-----------------------------
"I Think this Will Help"
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
I'm trying to capture the whole screen, paint it in my fullscreen window, then add effects to it (transitions and such).
I have a fealing I have to use CreateCompatibleDC but I can't figure out where.
Here is a simplified version of what my code looks like:
INT ScreenWidth = GetSystemMetrics(SM_CXSCREEN);
INT ScreenHeight = GetSystemMetrics(SM_CYSCREEN);
HDC DesktopDC = GetDC(0);//I do this before my window is displayed
HDC MyDC = GetDC(hWnd);//hWnd Is my window
BitBlt(MyDC,0,0,ScreenWidth,ScreenHeight,DesktopDC,0,0,SRCCOPY);//Trying to cover my window
Any one care to help? (WIN32 API only please)
Also could you show me how to double buffer for flicker free drawing?
P.S. GDI is tough
wWw.KruncherInc.cOm
|
|
|
|
|
|
Here is another example.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Anybody has some sample code regarding
MsiEnumProducts
and
MsiGetProductInfo
Yuvaraj N
|
|
|
|
|
Try here.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Hi all,
I have a combo box, which has certain fields being populated from an XML file.
when i click the drop down arrow of the combo box using mouse, it displays all the fields.
but I am unable to select any of them..I am able to select them using the keyboard by pressing up/down arrow,and also using the mouse wheel..
Is my mouse event not getting messaged, or any other problem..Pls give me some tips how do i solve this..
|
|
|
|
|
hi,
i have a critical application that i need to capture the event if it is being killed by user in taskmgr.exe or being killed by scheduler.
i just want to write the event to a log file.
how can i capture this event? any good way to do that?
thanks,
jim
|
|
|
|