|
Sorry, I mean, I want to send 12007, then 5007, right number after left number.
|
|
|
|
|
Is it a LIFO pattern? In this case std::stack[^] is your answer
|
|
|
|
|
econy wrote: I wonder what data structure is good for the above logic and application.
The problem in this question is that you didn't actually tell us a lot about the logic and application. You only told us about the scope of input values, and that these values are gathered in batches and processed (filtering out duplicates) before sending out.
You didn't tell us if anything of this is time-critical, or you're working with restricted amounts of memory - should we try to optimize for either?
Also, is it more important for the receiver to receive the data in a timely manner, requiring on-the-fly processing so you can send out the batch right after the end of the cycle - or can you afford to delay the processing until after receiving the last input of the cycle, before sending it out?
The answer to these questions will influence what algorithm to use, and the algorithm will influence what data structures to use.
|
|
|
|
|
Hi,
I am writing an application to receive a data from adapter. Adapter is brodcasting UDP data.
So in my case I have two adapter which is connected to same router having following IP information -
1. Adapter 1 :-
IP : 192.168.1.32
Default Gateway : 192.168.1.1
Subnet Mask : 255.255.255.0
2. Adapter 2 :-
IP : 192.168.4.33
Default Gateway : 192.168.4.1
Subnet Mask : 255.255.255.0
Here is the router detail :
Default Gateway : 192.168.1.1
Subnet Mask : 255.255.255.0
PC is also connected to same router.
Application written in C++ is configure to receive data from any IP address.
m_nFamily = AF_INET;
m_nType = SOCK_DGRAM;
m_nProtocol = IPPROTO_UDP;
m_SockAddr.sin_addr.s_addr = INADDR_ANY;
m_SockAddr.sin_family = AF_INET;
In my case I can receive data coming from Adapter 1 but can not receive data coming from Adapter 2.
But the data coming from both the adapter I can see in Wireshark.
Work around to receive data from Adapter 2 : To receive data from adapter 2, I need to change the wireless network connection property for IPV4 and need to change "obtain IP address automatically" to "Use the following address":
Used following data to configure manually :
IP : 192.168.4.31
Default Gateway : 192.168.4.1
Subnet Mask : 255.255.255.0
But after doing this application don't see the message coming from adapter 1.
But the data from both the adapter can be seen in wireshark.
My goal is to receive data from both the adapter simultaneously.
|
|
|
|
|
Have you tried binding your socket to the specific IP addresses?
|
|
|
|
|
Thanks for going through it.
I did not try to bind the socket with specific IP address.
Also this is not a requirement for me. I will give a try just to verify if it is possible but my intention is to receive data from all the adapter connected to same netwoek(router). Earlier I am using DHCP so that time it was not a problem for me cause all the adapter was getting the same default gateway but now I am switching to static where user can put any IP address with different default gateway.
|
|
|
|
|
Also as I can see the data in wireshark, looks like PC is receiving this data but it is not reaching to application
|
|
|
|
|
You will receive messages on the socket that you have created, which will bind to the first adapter. If you wish to receive on both then you need two sockets one bound to each IP address.
|
|
|
|
|
|
Thanks for your valuable suggestion. I am trying all this, I will update you once I will collect the result.
|
|
|
|
|
Hello everybody,
Currently all my C++ project are on a Windows XP machine. For database connections I’m using ado. In stdafx.h I have lines:
#import "c:\Program Files\Common Files\system\ado\msado15.dll" rename_namespace( "ado" ) rename("EOF", "ADOEOF")
#import "C:\Program Files\Microsoft SQL Server\80\Tools\Binn\Resources\1033\sqldmo.rll" no_namespace
And when it’s required I call
ado::_ConnectionPtr pConn = NULL;
hr = pConn.CreateInstance( __uuidof( ado::Connection ) );
Everything has been working fine.
But now I’m moving all my projects to Windows 7 machine. And it appears, that created .exe files are working fine on Windows 7 machine but on Windows XP ado pointer could not be created.
hr = pConn.CreateInstance( __uuidof( ado::Connection ) );
doesn’t create valid connection object.
Thank you in advance, any suggestions will be appreciated
|
|
|
|
|
|
Dear all:
I try to use global hook with WH_GETMESSAGE, but still failed.
It work only on my application, not global. My code show as below:
#pragma data_seg (".SHARED")
HHOOK g_hPreviousMsgHook = 0;
HINSTANCE g_hInstance = 0;
#pragma data_seg()
#pragma comment(linker, "/SECTION:.SHARED,RWS")
BOOL CSoundDllApp::InitInstance()
{
CWinApp::InitInstance();
g_hInstance = AfxGetInstanceHandle();
return TRUE;
}
BOOL InstallWinHook()
{
BOOL bReturn = TRUE;
g_hPreviousMsgHook = SetWindowsHookEx(WH_GETMESSAGE,
&MsgHookProcedure, g_hInstance, 0);
if(NULL == g_hPreviousMsgHook)
{
bReturn = FALSE;
}
return bReturn;
}
LRESULT CALLBACK MsgHookProcedure(int nCode, WPARAM wParam, LPARAM lParam)
{
if(0 > nCode)
return CallNextHookEx(g_hPreviousMsgHook, nCode,
wParam, lParam);
PMSG data = (PMSG)lParam;
switch(data->message)
{
case WM_POINTERDOWN:
Beep(0x7fff, 1000);
break;
}
return CallNextHookEx(g_hPreviousMouseHook, nCode, wParam,
lParam);
}
I set 0 into last parameter of setWindowsHookEx api, but it seem like not work.
Could someone tell me where's wrong, please?
Thanks for your help, Victor
|
|
|
|
|
|
Dear Richard:
It mean I just hook message only from application message queue, so I can not get message from anthor place?
When I touch on some applications, it works.
When I touch on desktop, it does not work.
How? Does it mean the touch message on desktop not exist in application message queue?
Thanks for your help, Victor
|
|
|
|
|
Sorry, my original message was incorrect (the MSDN description lacks clarity). This should capture all messages, not just those directed to your application.
|
|
|
|
|
Recently I want to find a general solution for std::wcout so that it can print out all unicode strings. but, after poking around on google, i can't find useful. I'm stuck here, anybody can help me?
_setmode(_fileno(stdout), _O_U16TEXT); won't work as expected.
Here is my current code snippet:
auto previousMode = _setmode(_fileno(stdout), _O_U16TEXT);
std::wifstream wifs;
wifs.imbue(std::locale(wifs.getloc(), new std::codecvt_utf16<wchar_t, 0x10ffff,
std::codecvt_mode(std::little_endian | std::consume_header)>));
wifs.open(L"F:\\重要网址.txt", std::ios_base::binary);
std::wstring line;
std::getline(wifs, line);
wcout << line << endl;
wifs.close();
wcout << endl;
cout << "∦" << endl;
std::wofstream wofs;
wofs.imbue(std::locale(wifs.getloc(), new std::codecvt_utf16<wchar_t, 0x10ffff,
std::codecvt_mode(std::little_endian | std::consume_header)>));
wofs.open(L"F:\\iMoney.txt", std::ios_base::binary | std::ios_base::ate);
wofs << line << endl;
wofs.close();
_setmode(_fileno(stdout), previousMode);
and here is some symbols to test your slution before post here:
∀, ∁, ∂, ∅, ∰, ∵, ∺, ⊙, ⋾, ⋻, ⋱, ⋭, ⋣, ⋧
Arabic: لطيفة الطقس اليوم
modified 26-Mar-14 6:16am.
|
|
|
|
|
int i = 0;
statement 1: if( i == 0 )
statement 2: if( !i )
Although the speed does not matters in this case, but I want to know the way above 2 statements are evaluated.
|
|
|
|
|
It depends on the compiler and the optimization options.
But in this simple case the generated code should be identical. You can check this by specifying a compiler option to generate assembly code (e.g. /Fas with Microsoft compilers) and compare the generated code.
|
|
|
|
|
I agree with you!
In general, two cases are identical!
|
|
|
|
|
You don't need to care; write readable code, the compiler will be more than sufficient to optimize it.
They will be compile to the same thing.
I'd rather be phishing!
|
|
|
|
|
I think the first one is faster.
because, the in second
- variable first ! converted
- the newly converted variable is converted to 1/0 for if statement
but in first-
-the == operator check bit wise datas of 2 numbers, if matched 1/if not 0.
so i think the first one is faster. Whats your view..
|
|
|
|
|
THERE IS NO DIFFERENCE.
For such simple code, the compiler will generate the same code.
compile and generate the assembly code for both versions, and you will see that the code is the same.
(testes with debug version on VS2012).
I'd rather be phishing!
|
|
|
|
|
shaktikanta wrote: I think the first one is faster.
The compiler need do nothing more than test for zero which the target CPU almost certainly has a single opcode for.
|
|
|
|
|
The second one is faster to type.
~RaGE();
I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus
Entropy isn't what it used to.
|
|
|
|