Hi,
I am working on a project involving contactless card and to read or
write into these cards we need some parameters (Key to use for instance).
My problem is to store these parameters in the most efficient way.
I was thinking first in a c manner as a struct array like this :
struct TFileInfo
{
int nSFID, // Short file ID
int nLID, // Long File ID
int nKey
};
// not sure of the syntax, it's been a long time I haven't used it
TFileInfo fileInfo[] =
{
{ 0x17, 0x3127, 0x0E },
{ 0x18, 0x3128, 0x08 },
};
and after I need to be able to get the values associated to nSFID.
ex :
CMyClass::GetKe y(int nSFID)
{
for (int i = 0; i < nItems; i++){
if (fileInfo[i].nSFID == nSFID)
return fileInfo[i].nKey
}
}
Or another solution would be to use a std::map<int, TFileInFo>
but I am concerned about performance. Besides I don't find the
initialization very elegant
std::map<int, TFileInfo> fileInfo;
TFileInfo stFileInfo;
stFileInfo.nSFI D = 0x17;
stFileInfo.nLID = 0x3127;
stFileInfo.nKey = 0x0E;
fileInfo[0x17] = stFileInfo;
stFileInfo.nSFI D = 0x18;
stFileInfo.nLID = 0x3128;
stFileInfo.nKey = 0x0E;
fileInfo[0x17] = stFileInfo;
I must add that my numbers of items will be 20 max.
If someone could inform me about this performance problem... 6 1785
Vince wrote: Hi,
I am working on a project involving contactless card and to read or write into these cards we need some parameters (Key to use for instance). My problem is to store these parameters in the most efficient way.
I was thinking first in a c manner as a struct array like this :
struct TFileInfo { int nSFID, // Short file ID int nLID, // Long File ID int nKey };
// not sure of the syntax, it's been a long time I haven't used it TFileInfo fileInfo[] = { { 0x17, 0x3127, 0x0E }, { 0x18, 0x3128, 0x08 }, };
and after I need to be able to get the values associated to nSFID. ex : CMyClass::GetKe y(int nSFID) { for (int i = 0; i < nItems; i++){ if (fileInfo[i].nSFID == nSFID) return fileInfo[i].nKey } }
this will take an average of 10 comparisions to find the value, if
there's 20 elements. A std::map will take an average of 4 comparisions.
And so, which is more efficient? A linear search is O(n) while a search
on a std::map is O(log n). Or another solution would be to use a std::map<int, TFileInFo> but I am concerned about performance. Besides I don't find the initialization very elegant
std::map<int, TFileInfo> fileInfo;
TFileInfo stFileInfo;
stFileInfo.nSFI D = 0x17; stFileInfo.nLID = 0x3127; stFileInfo.nKey = 0x0E; fileInfo[0x17] = stFileInfo;
stFileInfo.nSFI D = 0x18; stFileInfo.nLID = 0x3128; stFileInfo.nKey = 0x0E; fileInfo[0x17] = stFileInfo; I must add that my numbers of items will be 20 max.
If someone could inform me about this performance problem...
you might want to consider a std::set instead, since the key is
embedded into the TFileInfo struct. Then give your struct a an
operator<, or pass a functor as the 2nd template argument to std::set.
In any case, you can initialize a std::set or std::map with an array:
std::set<TFileI nfo> myset(fileInfo, fileInfo + 20); // where fileInfo
is the array you have above
A std::map expects iterators to std::pairs, which makes the
initialization a little more awkward:
// you must give TFileInfo a constructor
std::pair<int, TFileInfo> init[] =
{ std::make_pair( 0x17, TFileInfo(0x17, 0x3127, 0x0E)),
std::make_pair( ... , TFileInfo( ... )),
...
};
std::map<int, TFileInfo> mymap(init, init + 20);
Vince wrote: CMyClass::GetKe y(int nSFID) { for*(int*i*=*0; *i*<*nItems;*i+ +){ if (fileInfo[i].nSFID == nSFID) return fileInfo[i].nKey } }
If you sort your array 'fileInfo' by the nSFID field, then
you can have O(logN) lookup by using std::lower_boun d().
There's nothing wrong per se with POD arrays, esp. if they
can be const, and thus be put into read-only memory.
Marc
"Vince" <vs**@caramail. com> wrote in message
news:43******** *************** @news.free.fr.. . Hi,
I am working on a project involving contactless card and to read or write into these cards we need some parameters (Key to use for instance). My problem is to store these parameters in the most efficient way.
I was thinking first in a c manner as a struct array like this :
struct TFileInfo { int nSFID, // Short file ID int nLID, // Long File ID int nKey };
// not sure of the syntax, it's been a long time I haven't used it TFileInfo fileInfo[] = { { 0x17, 0x3127, 0x0E }, { 0x18, 0x3128, 0x08 }, };
and after I need to be able to get the values associated to nSFID. ex : CMyClass::GetKe y(int nSFID) { for (int i = 0; i < nItems; i++){ if (fileInfo[i].nSFID == nSFID) return fileInfo[i].nKey } }
Or another solution would be to use a std::map<int, TFileInFo> but I am concerned about performance. Besides I don't find the initialization very elegant
std::map<int, TFileInfo> fileInfo;
TFileInfo stFileInfo;
stFileInfo.nSFI D = 0x17; stFileInfo.nLID = 0x3127; stFileInfo.nKey = 0x0E; fileInfo[0x17] = stFileInfo;
stFileInfo.nSFI D = 0x18; stFileInfo.nLID = 0x3128; stFileInfo.nKey = 0x0E; fileInfo[0x17] = stFileInfo; I must add that my numbers of items will be 20 max.
If someone could inform me about this performance problem...
Performance questions are best answered by performance tests. Since there's
only 20 items, I'd bet that the difference between the array and std::map
wouldn't be significant unless your application performs this lookup very
frequently.
As Marc pointed out, sorting the entries and using a search routine is
another option. Also, if nSFID has a limited range, you could create an
array that can be indexed by the nSFID, giving you O(1) lookup time (but
possibly requiring a little more memory).
--
David Hilsee
Vince wrote:
Others have already talked about your 'performance' issue.
But ...
Besides I don't find the initialization very elegant
std::map<int, TFileInfo> fileInfo;
TFileInfo stFileInfo;
stFileInfo.nSFI D = 0x17; stFileInfo.nLID = 0x3127; stFileInfo.nKey = 0x0E; fileInfo[0x17] = stFileInfo;
stFileInfo.nSFI D = 0x18; stFileInfo.nLID = 0x3128; stFileInfo.nKey = 0x0E; fileInfo[0x17] = stFileInfo;
.... this can easily be cured.
Just provide your struct with a constructor:
struct TFileInfo
{
TFileInfo( int SFID, int LID, int Key )
: nSFID( SFID ), nLID( LID ), nKey( Key )
{}
int nSFID, // Short file ID
int nLID, // Long File ID
int nKey
};
and now you can ceasily create objects and initialize them
on the fly:
fileInfo[0x17] = TFileInfo( 0x17, 0x3127, 0x0E );
fileInfo[0x18] = TFileInfo( 0x18, 0x3128, 0x0E );
--
Karl Heinz Buchegger kb******@gascad .at
Alipha wrote: Vince wrote:
Hi,
I am working on a project involving contactless card and to read or write into these cards we need some parameters (Key to use for instance). My problem is to store these parameters in the most efficient way.
I was thinking first in a c manner as a struct array like this :
struct TFileInfo { int nSFID, // Short file ID int nLID, // Long File ID int nKey };
you might want to consider a std::set instead, since the key is embedded into the TFileInfo struct. Then give your struct a an operator<, or pass a functor as the 2nd template argument to std::set.
But how would you get the TFileInfo structure you're looking for? If I
want to use set::find(), I need to pass a struct TFileInfo, but I just
have a nSFID.
Mark
Capstar wrote: [snip]
But how would you get the TFileInfo structure you're looking for? If I want to use set::find(), I need to pass a struct TFileInfo, but I just have a nSFID.
Mark
create a TFileInfo with the nSFID field set to what you want then. If
you give your struct a one-argument ctor (probably explicit), then it
would be easy to do myset.find(TFil eInfo(0x17)). Of course, you lose
the ability to initialize your struct with { } initializers. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Jonathan |
last post by:
I am hoping that someone more experienced than myself can point me towards
what might be the fastest data lookup method to use for storing ip
addresses. My situation is that I will need to maintain a list of perhaps 50
ip addresses to be used in a packet sniffing application. For each packet
that goes through the application (which will be monitoring all traffic
through a switch), I need to see if an entry for the source ip of that
packet...
|
by: _link98 |
last post by:
Running DB2 ESE V8.1.8 on WinXP.
This is Fixpak 8.
Have a structured-type and some methods for that type.
One of my methods needs to do insert / update on tables.
The type specification includes "LANGUAGE SQL...CONTAINS SQL".
But I get SQL0374N "The MODIFIES SQL DATA clause has not been
specified for the CREATE FUNCTION statement for LANGUAGE function..."
|
by: Julie |
last post by:
What is the *fastest* way in .NET to search large on-disk text files (100+ MB)
for a given string.
The files are unindexed and unsorted, and for the purposes of my immediate
requirements, can't be indexed/sorted.
I don't want to load the entire file into physical memory, memory-mapped files
are ok (and preferred). Speed/performance is a requirement -- the target is to
locate the string in 10 seconds or less for a 100 MB file. The...
|
by: Loui Mercieca |
last post by:
Hi,
In my design i have a data structure used to store large amount of
numbers ( in the range of lots of thousands ). Each element contains 3 items
and the no of elements are dynamic.. of the form:
|
by: hoopsho |
last post by:
Hi Everyone,
I am trying to write a program that does a few things very fast
and with efficient use of memory...
a) I need to parse a space-delimited file that is really large,
upwards fo a million lines.
b) I need to store the contents into a unique hash.
c) I need to then sort the data on a specific field.
d) I need to pull out certain fields and report them to the user.
| |
by: Dharmesh |
last post by:
Hi every1,
I am learning ASP.NET and came accross problem of storing my classes object
and I want its scope to be request. Is there a way do that. I found the only
way to store structured values in with scope request was with ViewState, but
for the ViewState to work the page has to post back to itself. But my page
does not posts back.
I would really appreciate your help.
|
by: Mudcat |
last post by:
Hi,
I am trying to build a tool that analyzes stock data. Therefore I am
going to download and store quite a vast amount of it. Just for a
general number - assuming there are about 7000 listed stocks on the two
major markets plus some extras, 255 tradying days a year for 20 years,
that is about 36 million entries.
Obviously a database is a logical choice for that. However I've never
used one, nor do I know what benefits I would get...
|
by: Kyle Teague |
last post by:
What would give better performance, serializing a multidimensional array
and storing it in a single entry in a table or storing each element of
the array in a separate table and associating the entries with the entry
in the other table?
Having a separate table would result in two queries instead of one, but
you wouldn't have to deal with the overhead of serializing and
unserializing data.
-- Kyle
|
by: Klaas Vantournhout |
last post by:
Hi,
I have a question, which is just out of interest.
What is the fastest way to do an odd/even check with c++ and if needed
assembler.
Assume n is an unsigned integer like type (unsigned int, unsigned long
int), what is the fastest?
using the modulo operator
|
by: Mohamed Yousef |
last post by:
Thanks all ,
but there is still something i forget to state -sorry - all
communication will be via Http with a server
so data is received via Http
so local network solutions won't work
the problem really starts after receiving data in storing them without
much of a CPU/Memory usage and with a good speed
@James Mills : didn't understand fully what you mean and how it will
improve writting effciency
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |