|
""For efficiency you can do it in jumps of a jump factor [say 256]. Have another member variable which has the count of array items.""
what do you mean i can do it in jumps?
|
|
|
|
|
Each time they add a new element to the array, if you are going to delete the current internal array and create a new one, your array would not be a very efficient tool. So assign memory in blocks of 256 or 512. Thus when they keep adding elements, we only change our element count. But the moment they cross 256, we delete our internal int* and new a new int* with an extra 256 [or whatever the jump factor]
Nish
Sonork ID 100.9786 voidmain
www.busterboy.org
If you don't find me on CP, I'll be at Bob's HungOut
|
|
|
|
|
sorry for asking to many questions(i hate it myself);
but what do you mean by "So assign memory in blocks of 256 or 512"
how do you do this without creating an array of a certain size other than one.
thanks!
|
|
|
|
|
new_array = new char[new_count * block_size];
if(sizeof (new_array) > sizeof (old_array) )
memcpy(new_array,old_array,sizeof old_array);
else
memcpy(new_array,old_array,sizeof new_array);
delete old_array;
Sonork ID 100.9786 voidmain
www.busterboy.org
If you don't find me on CP, I'll be at Bob's HungOut
|
|
|
|
|
Everything that Nish has explained to you, I explained earlier. You should stop assuming you asked the question badly, and start assuming you need to do some study to get to a point of being able to understand the answer.
Nish is saying ( as I said ) that it's more efficient to allocate more memory than you need, and keep track of what you've used, then reallocate another block as needed, than to expand the reserved memory every time you add to it.
The post that pointed out an ATL header which contains a simple array class is all the answer you need - look at the class he is recommending and you'll see an example implimntation of what you need. Naturally you should use this to learn, not just copy it.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
well thanks to both of you.
and sorry for misundestanding what you wrote Christian.
I really did not want the code I just want the idea how it should work;
but anyways thanks you two again, if you guys are there answering every question i post, I wonder how you all make your livings. i mean it's just insane coz you guys are here 16 hours a day. I could tell from how often you post stuff.
|
|
|
|
|
Marwan wrote:
wonder how you all make your livings. i mean it's just insane coz you guys are here 16 hours a day.
We are all employed by Chris Maunder of Code Project.
I make 480K annually
CG makes a little bit less on account of his lack of C# skills. That's why he is learning C# now
Nish
Sonork ID 100.9786 voidmain
www.busterboy.org
If you don't find me on CP, I'll be at Bob's HungOut
|
|
|
|
|
Nish [BusterBoy] wrote:
I make 480K annually
Based on your previous comments of how much people in India get an hour, this means you work 1315 hours a day, every day.
Nish [BusterBoy] wrote:
CG makes a little bit less on account of his lack of C# skills. That's why he is learning C# now
Oh, you're taking about clam shells ? Yeah, I make a bit less than 480,000 clam shells a year. I'm gonna catch up though, once I get into this C# stuff.....
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
Christian Graus wrote:
Based on your previous comments of how much people in India get an hour, this means you work 1315 hours a day, every day.
Cruel, cruel man!
Christian Graus wrote:
Oh, you're taking about clam shells ? Yeah, I make a bit less than 480,000 clam shells a year. I'm gonna catch up though, once I get into this C# stuff.....
LOL
Nish
Sonork ID 100.9786 voidmain
www.busterboy.org
If you don't find me on CP, I'll be at Bob's HungOut
|
|
|
|
|
i think you guys really need a raise
i'll probably ask your employer, i will tell him how much i irritate you guys with my stupid questions all the time, but you all never get tired of replying to the best of your knowledge.
|
|
|
|
|
In our EPos program (running on a Win98 computer), I am using the "_inp" and "_outp" functions to get the status of the Credit Card reader (attached to the Keyboard).
The commands are:
Keyboard Status Enquiry
_inp(0x64);
Enable Card Reader
_outp(0x60, 0xd3);
Disable Card Reader
_outp(0x60, 0xd4);
These commands always crash the Win2k machine, I guess it has something to do about reading/writting to an address.
So is there a LEGAL (or EASY) way of reading/writting this data to the Keyboard port on a Win2k machine, or is the keyboard located at a different port ?.
Any help would do - honest.
|
|
|
|
|
KB article Q112298 discusses this - on NT IN OUT instructions are privileged.
I'm surprised you can do this on 98. Learn something every day, I guess.
|
|
|
|
|
Hello!
My application uses Windows tray, and if the dialog is hiding and a second instance of the program is started, this function opens the first instance and exits the second one. This works very well if I have has the dialog opened (thus visible). If not, the first instance doesn’t come up. Why not??
I’m sorry about my bad English.
/Ola Carlsson
void CMyDlg::CheckInstance()
{
CWnd *temp = FindWindow(NULL, "My Dialog");
if(temp !=NULL)
{
temp->ShowWindow(SW_SHOWNOACTIVATE);
temp->SetForegroundWindow();
exit(0);
}
|
|
|
|
|
FindWindow should find both visible and not-visible windows. I believe you are destroying the dialog each time and not just show/hide flipping it.
Anyway you'd be better off, using a mutex. Read Joe Newcomer's article on avoiding multiple instances.
Nish
Sonork ID 100.9786 voidmain
www.busterboy.org
If you don't find me on CP, I'll be at Bob's HungOut
|
|
|
|
|
Hi,
I have to communicate with a slow device over the serial port.In order to preserve responsivness, the device is called from worker threads.
Problem:
Is it safe to access a BOOL CWinApp::m_bConnected from several worker threads at a time?
Since I am that familiar with mutexes and critical sections, how to achieve this?
Thanks
Pepe
|
|
|
|
|
Create a critical section and enter it every time you're going to use the BOOL. Then leave it right away. That way if one thread is accessing the BOOL, others will stop and wait for it to finish.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
A BOOL is atomic (only needs 1 processor instructor to read/write) and therefore does not need synchronising.
|
|
|
|
|
How can I get the coordination of clientdc?
Mazy
Don't Marry a Person You Can Live With...
Marry Someone You Can Not Live Without
|
|
|
|
|
BOOL GetClientRect(
HWND hWnd, // handle to window
LPRECT lpRect // client coordinates
);
For the cleint Area
|
|
|
|
|
I new to using VC++ but have experience with C and Visual Basic. I'm looking for a simple function to Read from a text file.
Something like in VB:
Set fs = CreateObject("Scripting.FileSystemObject")
set filename = fs.GetFile("Text.txt")
Set ts = filename.OpenAsTextStream(ForReading, TristateUseDefault)
Buffer = ts.Readline
Any example info I've found so far about File I/O in VC++ is exceedingly difficult. I'm writing an simple MFC dialog app.
Thanks.
|
|
|
|
|
try this:
FILE *fp;
fp = fopen(filename, "r");
ASSERT(fp!=NULL);
char * buffer[MAX_LINE_SIZE];
fgets(buffer, MAX_LINE_SIZE, fp);
// here, buffer contains one line from your file.
|
|
|
|
|
CStdioFile f;
if (f.Open(filename, CFile::modeRead)==0)
{
...error
}
CString csText;
if (!f.ReadString(csText))
{
....error
}
Smaller Animals Software, Inc.
You're the icing - on the cake - on the table - at my wake. Modest Mouse
|
|
|
|
|
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
#include <iostream>
#include <sstream>
using std::copy;
using std::vector;
using std::string;
using std::ifstream;
using std::ostream_iterator;
using std::cout;
using std::back_inserter;
using std::getline;
using std::ostringstream;
using std::istream_iterator;
int main(int argc, char* argv[])
{
string currentLine;
ifstream str("c:\\winzip.log");
if (!str.is_open())
{
cout << "It's stuffed\n";
return -1;
}
vector<string> file_contents;
copy(istream_iterator<string>(str),istream_iterator<string>(), back_inserter(file_contents));
// Now print out the results
copy(file_contents.begin(), file_contents.end(), ostream_iterator<string>(cout, "\n"));
return 0;
}
This example reads a file in and prints the output to the console. However, the pertinent point is that you can create an fstream, which is bidirectional, or just an ifstream or ofstream, and then if you know the file format, you can, for example, do this:
myFile >> nMyNumber >> szMyString >> etc.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
Hey! The guy is coming from VB. Are you going to make him afraid of C++?
I vote pro drink
|
|
|
|
|