|
It will not create any problem, since U R allocating 2 bytes of memory for the pointer "word" in the structure.
sizeof(struct _wordTable) -> This will always evaluates to 4 bytes
irrespective of the size of the string that "word" is pointing to.
Regards,
Arun Kumar.A
|
|
|
|
|
Hi:
Thank you. I was confused here for a second.
Thank you a lot, Arun.
|
|
|
|
|
Arun.Immanuel wrote: This will always evaluates to 4 bytes
Actually it will be 8 bytes when 32 bit addressing is used:
a pointer is usually stored as 4 bytes and the int is also 4 bytes.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
That will work.
Here is a better design that MS used for years.
typedef struct _wordTable {
int count;
char word[1];
} WORDTABLE;
WORDTABLE *word_ptr = malloc(sizeof(WORDTABLE) + wordSize);
if( word_ptr )
word_ptr->count = wordSize;
With this method you allocate both at the same time and do not have to add 1, because the extra byte it is part of the structure.
Note: You do not need to multiply by sizeof(char) on most compilers, because it is equal to 1.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
while (!bEnd)<br />
{<br />
Sleep(0);<br />
}
and
HANDLE hEventEnd = CreateEvent(...);<br />
WaitForSingleObject(hEventEnd...);
----------------------------------------------
which better?
|
|
|
|
|
HOW WHAT wrote: hile (!bEnd)
{
Sleep(0);
}
is obviously a disaster.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
|
Sleep(0) plainly does nothing, and so you're going to start another thread, but at the same time, have your main thread check a bool over and over again, as fast as it can ?
The mechanisms like WaitForSingleEvent exist precisely to stop people doing stuff like a hard loop to check a bool.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
e...But i see WaitForSingleObject sources also use do {}while(...), Sleep and WaitForSingleObject sources as much as same....
|
|
|
|
|
CPU resources... a while the is always looping takes al the computer resources in order to be done as fast as possible, in the other way is like a callback, the OS handles it...
|
|
|
|
|
|
I've given my five to Mr. Graus...
|
|
|
|
|
I have two functions:
getBuffer();
setBuffer();
Assuming the client calls setBuffer() and passes a pointer to a memory block where data is stored, would it be bad practice to have my object modify that block directly, possibly resizing the block itself?
Doing this seems bad practice, as it would indirectly make getBuffer() pointless, but resizing the memory block would screw everything up wouldn't it? Or does the fact the buffer is completed by a NULL byte allow for such scenarios?
Hopefully my question has made sense?
Cheers
I'm finding the only constant in software development is change it self.
|
|
|
|
|
Hockey wrote: would it be bad practice to have my object modify that block directly, possibly resizing the block itself ... but resizing the memory block would screw everything up wouldn't it
Modify how ?
Resizing would be bad as you probably haven't specified what heap the block is from.
Even if you are using alloc/free new/delete everywhere there may be issues (if multiple modules have statically linked to CRT).
...cmk
Save the whales - collect the whole set
|
|
|
|
|
Interesting! Yes it would be bad practice to have the object modify the size of a buffer it knows nothing about, but it would also be bad practice not to have the object do its own buffer allocations and releases.
Example: char buffer[128]; setBuffer(buffer, cbSize);
As you can see, I just misused your function.
Unless you have a very good reason not to, then you should use the C++ vector class for your buffers. If your object needs a buffer it should allocate it internally and have control over its life time.
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|
Has anyone out there ever successfully done automatic proxy detection?
To be specific -- there's 2 types. There's configuration from IE's static settings.
But IE also supports a automatic proxy detection javascript -- FindProxyForUrl?
I am having a heck of a time finding a method that works.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.soonr.com">SoonR Inc.</A>
|
|
|
|
|
How can I set the uniform axis property of mschart in VC++2005?
in VB we can use .plot.UniformAxis=FALSE
But how can we do that in VC?
thanks!
|
|
|
|
|
is there anybody who knows that?
|
|
|
|
|
chart.GetPlot().SetUniformAxis()?
|
|
|
|
|
|
What do you mean?
|
|
|
|
|
GetPlot()should be get_Plot()
but no this function, set_UniformAxis().
|
|
|
|
|
Well, I don't know, you could always open directly the ocx control with the ole/view utility that comes with VC++6, if you don't have that VC++ you can download it from Microsoft.
In that utility you can always choose the first option in the first menu and view the typelib (selecting the same ocx) and then you'll be able to see all that that control exports.
Then you shold be able to see how to do that.
An ActiveX control has it's members inside, so all the languages that must use it should be able to do it. A couple of weeks ago, I was not able to reach a couple of functions in an OCX from VC++2005 and in fact it was possible from Delphi.
Hope this helps.
|
|
|
|
|
I have a c++ codes for programming the parallel port to control an interfce circuit of 8 electrical devices.But this code did not work on WIN XP.how can convert these codes to visual c++ in order for me to incorporate inpout32.dll.Thanks
this is the code:
/*program to control devices using PC parallel port
The devices are controlled by pressing the keys 1-8
that corresponds to each of the 8 possible devices
*/
#include<dos.h>
#include<stdio.h>
#include<conio.h>
#define PORT 0x378 /* This is the parallel port address */
main()
{
char val=0,key=0;
char str1[]="ON ";
char str2[]="OFF";
char *str;
clrscr();
printf("Press the approriate number key to turn on/off devices:\n\n");
printf("Here Device1 is connected to D0 of parallel port and so on\n\n");
printf("Press \"x\" to quit\n\n");
gotoxy(1,8);
printf("Device1:OFF Device2:OFF Device3:OFF Device4:OFF\n");
printf("Device5:OFF Device6:OFF Device7:OFF Device8:OFF");
while(key!='x' && key!='X')
{
gotoxy(1,12);
printf("Value in hex sent to the port:");
key=getch();
switch(key){
case '1':
gotoxy(9,8);
val=(val&0x01)?(val&(~0x01)):val|0x01;
str=(val&0x01)?str1:str2;
printf("%s",str);
outportb(PORT,val);
gotoxy(1,13);
printf("%x",val);
break;
case '2':
gotoxy(21,8);
val=(val&0x02)?(val&(~0x02)):val|0x02;
str=(val&0x02)?str1:str2;
printf("%s",str);
outportb(PORT,val);
gotoxy(1,13);
printf("%x",val);
break;
case '3':
gotoxy(33,8);
val=(val&0x04)?(val&(~0x04)):val|0x04;
str=(val&0x04)?str1:str2;
printf("%s",str);
outportb(PORT,val);
gotoxy(1,13);
printf("%x",val);
break;
case '4':
gotoxy(45,8);
val=(val&0x08)?(val&(~0x08)):val|0x08;
str=(val&0x08)?str1:str2;
printf("%s",str);
outportb(PORT,val);
gotoxy(1,13);
printf("%x",val);
break;
case '5':
gotoxy(9,9);
val=(val&0x10)?(val&(~0x10)):val|0x10;
str=(val&0x10)?str1:str2;
printf("%s",str);
outportb(PORT,val);
gotoxy(1,13);
printf("%x",val);
break;
case '6':
gotoxy(21,9);
val=(val&0x20)?(val&(~0x20)):val|0x20;
str=(val&0x20)?str1:str2;
printf("%s",str);
outportb(PORT,val);
gotoxy(1,13);
printf("%x",val);
break;
case '7':
gotoxy(33,9);
val=(val&0x40)?(val&(~0x40)):val|0x40;
str=(val&0x40)?str1:str2;
printf("%s",str);
outportb(PORT,val);
gotoxy(1,13);
printf("%x",val);
break;
case '8':
gotoxy(45,9);
val=(val&0x80)?(val&(~0x80)):val|0x80;
str=(val&0x80)?str1:str2;
printf("%s",str);
outportb(PORT,val);
gotoxy(1,13);
printf("%x",(unsigned char)val);
break;
}
}
}
|
|
|
|
|
You need to create a low level driver, as modern operating systems do not normally allow you to access the hardware directly.
Good news: There is a freeware version that will allow you to do this; just install and call.
Bad news: I do not remember its name, but if I could find it while researching the subject, 5 years ago, so can you.
Good Luck!
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
|
|
|
|
|