|
Stephen Hewitt wrote: transform(isi, isi_end, back_inserter(s), ::tolower);
Then this solution is very much similar to my previous one (URL[^]). Both of them copy the file buffer to a string. The only difference is that your solution requires to do file >> noskipws; in addition because file.rdbuf() keeps the spaces and the newlines whereas another way does not.
Maxwell Chen
|
|
|
|
|
Hi all,
May this question can be odd to you, if so I'm really sorry.
I've write a simple server application which is used to make a chat window. Actually there is two chat windows on the same HTML page. Whatever I type on one window is displayed on the other. Now I want to automatically run the server, without pressing F5 and start, at predefined time. I think it is clear to you.
One of my friend says that, using global mutex, I think it is the right word I can do that. But I don't know anything about it. Can you guys give me a help on it.
Thanks a lot...
I appreciate your help all the time...
Eranga
|
|
|
|
|
I have an std::map and I want to use std::for_each and boost::bind to call a method on the 'second' object in each map node. Anyone know the correct syntax?
class MyType
{
public:
void Method()
{
}
};
std::map<int, MyType> aMap;
this is what I can get right...
std::for_each(aMap.begin(), aMap.end(), boost::bind(&MyType::Method))
|
|
|
|
|
This works for me:
#include "stdafx.h"
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <functional>
#include <boost/bind.hpp>
using namespace std;
class MyType
{
public:
MyType(const string &name) : m_name(name) {}
void Method()
{
cout << m_name << endl;
}
private:
string m_name;
};
typedef std::map<int, MyType> Map_t;
int main(int argc, char* argv[])
{
Map_t m;
m.insert(Map_t::value_type(1, MyType("One")));
m.insert(Map_t::value_type(2, MyType("Two")));
m.insert(Map_t::value_type(3, MyType("Three")));
m.insert(Map_t::value_type(4, MyType("Four")));
m.insert(Map_t::value_type(5, MyType("Five")));
for_each(m.begin(), m.end(), boost::bind(&MyType::Method, boost::bind(&Map_t::value_type::second, _1)));
return 0;
}
Steve
|
|
|
|
|
Thanks mate
Someone here pointed out to me that this is not an efficient way of doing this as the bind is called once for each item in the sellection.
|
|
|
|
|
Josh Gray wrote: Someone here pointed out to me that this is not an efficient way of doing this as the bind is called once for each item in the sellection.
Perhaps... I haven't looked at the generated machine code in a release build so I can't say with certainty. You’d hope that on a decent compiler the function calls would be optimized away as they’re inline.
Nevertheless, that’s what’s required to use boost::bind in the situation you described.
Steve
|
|
|
|
|
Hi,
I am trying to store a large set of "words," with "definitions," using a trie structure. The code will be written as a DLL, but I want this table to be static so that the table doesn't have to be reread every time a function from this DLL is called. The problem I have is the size of the table. When I create the object, the dictionary, used to hold these words, I can only create a fraction of the number of nodes that are needed. Is there any way I can write a container class so that each member, or set of members, of the class resides at a different location in memory? That way I can avoid the current problem of not having a contiguous block of memory large enough to hold my object.
Alternatively another option is to make multiple dictionary objects. However I have two problems with this approach.
1) Since I need the object to be globally static, I have no way of dynamically creating multiple objects. I would have to pre-declare them and use them as needed. That would suck up memory and is in general fairly messy.
2) Another problem is the matter of efficiency. The more nodes I can fit into one object, the more efficient the storage. One object containing 1M nodes can store more than 2 objects of 500,000 nodes.
Thanks.
|
|
|
|
|
gluballs wrote: That way I can avoid the current problem of not having a contiguous block of memory large enough to hold my object.
How about std::map?
|
|
|
|
|
I experimented with using maps for this application and I remembered it was not very efficient when dealing with a large number of keys (I have a table of approx 40M words). Would maps not have this memory allocation problem? For example, can I keep appending to a map object if it's memory exceeds the largest contiguous memory block on my machine?
|
|
|
|
|
gluballs wrote: For example, can I keep appending to a map object if it's memory exceeds the largest contiguous memory block on my machine?
Yep because each node is allocated individually.
However..
gluballs wrote: 40M words
...thats a lot of items. Have you looked into memory mapped files?
|
|
|
|
|
Josh Gray wrote: Yep because each node is allocated individually.
How is that done? For my object I create space for it by using allocator class. I assumed (or rather hoped) that multiple calls to allocate memory might result in accessing another separate block. So something like this would work:
void Dictionary::grow(){
blah = alloc.allocate(max);
blah2 = alloc.allocate(max);
// stuff
}
this however does not have the desired effect.
Josh Gray wrote: ...thats a lot of items. Have you looked into memory mapped files?
Nope. Never heard of them until now, but they do sound interesting. thanks for the hint.
|
|
|
|
|
Im not sure I really follow you and I need to leave the office for the day. have a look at the soufrce for an stl map implementation and see what its doing internally.
|
|
|
|
|
Josh Gray wrote: Yep because each node is allocated individually.
This problem could be potentially solved by using an allocator such as available in the Boost Pool Library[^] library. In particular pool_alloc[^]
Steve
|
|
|
|
|
gluballs wrote: 2) Another problem is the matter of efficiency.
If you are using a binary tree, the average depth would be O(sqrt(N)). If you used a binary search tree instead, the average depth would be O(log N).
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Halo~ I find some difficulties on accessing a .bin file.
I want to read particular bit in a .bin file. I tried to search the solution in the web but still cannot get the solution.
For example, I have a test.bin file which contains the data "1101010101011100". How can I read the 3rd and 4th bit (i.e. "01")?
It would be prefect if anyone can give me a complete source code. Many many thanks to you
Kennis
|
|
|
|
|
Read a byte from the .bin file and by using the bitwise operator (&), required bits can be fetched.
Come online at:-
jubinc@skype
|
|
|
|
|
Is Pointers and references are same, because their assembly language instructions looks the same.
VIBIN
"Fool's run away,where angle's fear to tread"
|
|
|
|
|
They are very similar but not the same. Once you get down to the machine code level that are identical however.
Steve
|
|
|
|
|
Internally reference is implemented as a pointer. The compiler take care about that. That is why the assembly language instructions looks the same. But we u can notify the following differences between a pointer and a reference.
1. a pointer is a variable holding an address of another variable.
2. u can reuse a pointer variable but this is not possible for a reference. or u can assign another address to a pointer variable.
3. u need to use * or -> operator to access the content of a pointer.
4 . there is a possibility of null reference for a pointer, so u need to check like
char *p = new char [MAX_PATH];
.....
.....
if(p)
{
.....do something
}
else
{
do something
}
i think the above will help to understand the things
|
|
|
|
|
I am developing a COM exe using ATL in Visual Studio 2005 .
I have a list control in a ATL dialog however I cannot get it to show any text .
I am adding the code to display some status in the List Control but fail to display anything
LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)<br />
{<br />
<br />
CAxDialogImpl<catlstatusdlg>::OnInitDialog(uMsg, wParam, lParam, bHandled);<br />
WCHAR str[] = _T("Initialization Done");<br />
SendDlgItemMessage(IDC_LIST1,LB_ADDSTRING , 0 , (LPARAM)&str); bHandled = TRUE;<br />
<br />
<br />
<br />
<br />
<br />
return 1;
}</catlstatusdlg>
Am I missing something here or doing this initialization at the wrong place ?
Help is appreciated
div class="ForumSig">Engineering is the effort !
|
|
|
|
|
act_x wrote: I am adding the code to display some status in the List Control
If you are using list control, LB_ADDSTRING is wrong message to send. LB_ADDSTRING is used to insert item into list box. Use the LVM_INSERTITEM message.
|
|
|
|
|
Hi, I wondering if it is possible to call a main with its parameters from another method?
From the example shown below.
<br />
<br />
int test(int argc, char *argv[])<br />
{<br />
<br />
}<br />
<br />
<br />
void example()<br />
{<br />
test(int argc, char *argv[]);<br />
}<br />
Can can the parameters be altered in the example method which doesn't mean altering the parameter list in the test()?
|
|
|
|
|
It is possible to call the main function from another function. but the
int argc, char *argv[] in example method are local variables of example. u cannot access the int argc, char *argv[] in main from example.
|
|
|
|
|
main is a function hence you can call it from another function (but then you have to find a way to stop recursion).
There isn't main in the posted code.
gman2008 wrote: void example()
{
test(int argc, char *argv[]);
}
The above code is wrong, use, for instance
void example()
{
char * argv[]={"appname", "foo"};
test(2, argv);
}
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
thanks thats has sorted out the problem
|
|
|
|