Click here to Skip to main content
15,890,123 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Format Conversion Pin
David Crow30-Nov-04 3:03
David Crow30-Nov-04 3:03 
GeneralDialog Resource Problem Pin
Member 1697729-Nov-04 21:51
Member 1697729-Nov-04 21:51 
Questionhow to restricted browser Pin
vc-programmer-29-Nov-04 21:43
vc-programmer-29-Nov-04 21:43 
AnswerRe: how to restricted browser Pin
ThatsAlok30-Nov-04 0:58
ThatsAlok30-Nov-04 0:58 
Questionwhat the hell is this grammar all about Pin
LiYS29-Nov-04 21:20
LiYS29-Nov-04 21:20 
AnswerRe: what the hell is this grammar all about Pin
Steve S29-Nov-04 21:34
Steve S29-Nov-04 21:34 
GeneralRe: what the hell is this grammar all about Pin
LiYS29-Nov-04 21:45
LiYS29-Nov-04 21:45 
GeneralRe: what the hell is this grammar all about Pin
benjymous29-Nov-04 22:38
benjymous29-Nov-04 22:38 
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; // 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;
}

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!

GeneralRe: what the hell is this grammar all about Pin
LiYS29-Nov-04 22:53
LiYS29-Nov-04 22:53 
GeneralRe: what the hell is this grammar all about Pin
benjymous29-Nov-04 22:59
benjymous29-Nov-04 22:59 
GeneralRe: what the hell is this grammar all about Pin
LiYS29-Nov-04 23:08
LiYS29-Nov-04 23:08 
AnswerRe: what the hell is this grammar all about Pin
David Crow30-Nov-04 3:09
David Crow30-Nov-04 3:09 
Generalhighlighting a portion of a bitmap Pin
Arrun29-Nov-04 19:57
Arrun29-Nov-04 19:57 
QuestionFunction Parameters in a C DLL? Pin
Arsalan Malik29-Nov-04 19:41
Arsalan Malik29-Nov-04 19:41 
AnswerRe: Function Parameters in a C DLL? Pin
basementman30-Nov-04 4:45
basementman30-Nov-04 4:45 
GeneralRe: Function Parameters in a C DLL? Pin
Arsalan Malik30-Nov-04 16:53
Arsalan Malik30-Nov-04 16:53 
GeneralOLE2ANSI issue in VS.Net 2003 Pin
sajpt29-Nov-04 19:36
sajpt29-Nov-04 19:36 
GeneralRe: OLE2ANSI issue in VS.Net 2003 Pin
El'Cachubrey29-Nov-04 20:25
El'Cachubrey29-Nov-04 20:25 
GeneralRe: OLE2ANSI issue in VS.Net 2003 Pin
sajpt29-Nov-04 20:48
sajpt29-Nov-04 20:48 
GeneralRe: OLE2ANSI issue in VS.Net 2003 Pin
sajpt29-Nov-04 23:22
sajpt29-Nov-04 23:22 
GeneralReading function signature from DLL... Pin
Orkun GEDiK29-Nov-04 18:50
Orkun GEDiK29-Nov-04 18:50 
GeneralRe: Reading function signature from DLL... Pin
ThatsAlok29-Nov-04 19:00
ThatsAlok29-Nov-04 19:00 
GeneralRe: Reading function signature from DLL... Pin
Orkun GEDiK29-Nov-04 20:43
Orkun GEDiK29-Nov-04 20:43 
GeneralRe: Reading function signature from DLL... Pin
ThatsAlok30-Nov-04 1:11
ThatsAlok30-Nov-04 1:11 
GeneralCopy Screen Pin
Timothy Grabrian29-Nov-04 18:09
professionalTimothy Grabrian29-Nov-04 18:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.