|
Hi every one!
Is this a safe way to define key structure.If not then how'd it be safer
Thanks!
typedef struct _key
{
struct p1
{
struct p2
{
unsigned char a1[128];
unsigned char a2[8];
};
unsigned char b1[64];
unsigned char b2[64];
unsigned char b3[128];
unsigned char b4[64];
unsigned char b5[64];
unsigned char b6[64];
};
}
KEY;
|
|
|
|
|
What do you mean safe? Type safe, thread safe, OO safe, exception safe or just proof against terrorist bombing?
"The secret of happiness is freedom, and the secret of freedom, courage."
Thucydides (B.C. 460-400)
|
|
|
|
|
I mean safe by the fact that these arrays are big and many, or would it be a problem in memory ?
Also is it Thread safe?.
And is it OO safe because i will use it in a class
Thanks!
|
|
|
|
|
It wouldn't be a problem in memory, it will just use up quite a bit of it And being thread safe is only a problem if you have two or more threads trying to access the same bit of data at the same time. It is perfectly OO-safe unless it is a private/protected member and you are trying to access it from outside the class
Hope this helps,
--Perspx
"The Blue Screen of Death, also known as The Blue Screen of Doom, the "Blue Screen of Fun", "Phatul Exception: The WRECKening" and "Windows Vista", is a multi award-winning game first developed in 1995 by Microsoft" - Uncyclopedia
Introduction to Object-Oriented JavaScript
|
|
|
|
|
Dennis L wrote: safe by the fact that these arrays are big and many
That will depend on what error checking you have active when you allocate the structure, rather than on the structure itself and how much memory is available of course.
Dennis L wrote: Also is it Thread safe?.
Not as presented. There's nothing inherent in this structure to prevent multiple contexts accessing it asynchronously.
Dennis L wrote: And is it OO safe because i will use it in a class
Not as presented. The data members should ideally all be private (data hiding), all access should be via accessor functions, default constructirs, copy constructors and possibly equivalence/comparison operators may need to be provided.
Having said that it's a good start to get your fundamental data structures right for the job. All the rest can then be added and you know you're not wasting your time.
"The secret of happiness is freedom, and the secret of freedom, courage."
Thucydides (B.C. 460-400)
|
|
|
|
|
About the OO safe question
i will use it like:
class MYCLASS
{
...
...
public:
KEY k; or KEY *k;
...
};
|
|
|
|
|
Hmm, that's not very OO. Google up some terms like 'data hiding' and 'design by contract' to get ideas on 'better' ways.
"The secret of happiness is freedom, and the secret of freedom, courage."
Thucydides (B.C. 460-400)
|
|
|
|
|
Sorry! If KEY is a private member?
Or what if i do it like
class MYCLASS
{
...
...
public:
void Get(KEY *k);
...
};
// in cpp
void MYCLASS::Get(Key *k)
{
// Do operation:
}
int main()
{
MYCLASS g;
KEY k; // key is empty
g.Get(&k);
//key is filled
// Do operations with k
return 0;
}
|
|
|
|
|
Yep, you can do it that way. It's not really the usual way to do things but you can do it that way if you wish. It would be more normal to write the functions that do operations with k as members of MYCLASS which use the private member k to do their work and return results to their callers e.g. Key validity.
"The secret of happiness is freedom, and the secret of freedom, courage."
Thucydides (B.C. 460-400)
|
|
|
|
|
What is the difference to use it as KEY k; and KEY *k;
I have read some papers that say that there is speed difference or some kind of difference in memory.
(if i remember well)
Or what is the difference anyway?
|
|
|
|
|
If you're unsure of the difference between KEY k; an instance of KEY called k and KEY* k; an instance, called k, of a pointer to a KEY, then you really shouldn't be attempting any serious development in C++. Seriously I'm not being rude you need to read some books, go on a course or whatever or things will get very painful very quickly. C++ is not like BASIC or even VB. You can't really learn it from scratch by trial and error, you have to start from a certain base in order to stand a chance. At the very least read some Web tutorials on pointers before diving in or both the contents of your PC and your sanity are at risk.
"The secret of happiness is freedom, and the secret of freedom, courage."
Thucydides (B.C. 460-400)
|
|
|
|
|
Maybe i didn't ask right the question.
I know the difference between KEY k; and KEY *k; but i really care that the fact *k is allocated in free memory has some advantages?
|
|
|
|
|
OK but if you use a member instance
<br />
class CMyClass<br />
{<br />
private:<br />
KEY k; <br />
};<br />
then k is allocated wherever the instance of your class is allocated. You can use
heap
<br />
CMyClass* pMyInstance = new CMyClass();<br />
or stack
<br />
CMyClass MyInstance;<br />
If you're allocating really large amounts of data you definitely need the heap, possibly even look into the Virtual Memory API. In general its often best to leave the decision on where to allocate data up to the code that uses the data rather than trying to make it part of the data.
"The secret of happiness is freedom, and the secret of freedom, courage."
Thucydides (B.C. 460-400)
|
|
|
|
|
Putting a * there means that it is a pointer to a KEY structure, whereas no * means that it is actually a KEY structure and the required memory to hold all the KEY data is set aside for it.
Regards,
--Perspx
"The Blue Screen of Death, also known as The Blue Screen of Doom, the "Blue Screen of Fun", "Phatul Exception: The WRECKening" and "Windows Vista", is a multi award-winning game first developed in 1995 by Microsoft" - Uncyclopedia
Introduction to Object-Oriented JavaScript
|
|
|
|
|
Do you mean is it safe to define a structure within a structure?
Regards,
--Perspx
"The Blue Screen of Death, also known as The Blue Screen of Doom, the "Blue Screen of Fun", "Phatul Exception: The WRECKening" and "Windows Vista", is a multi award-winning game first developed in 1995 by Microsoft" - Uncyclopedia
Introduction to Object-Oriented JavaScript
|
|
|
|
|
Watch out for memory alignment issues if you are going to use these keys (I'm assume they will be crypto keys) with raw memory access. You can change the way the object is laid out in memory with the #pragma pack directive. It may not be a problem though, depends on how you'll use your struct (Actually it would show not so great design if you'd need this, but there may be performance reasons).
|
|
|
|
|
helle everyone...
i need help. how to create mfc aplication installer...
i mean i want to make my program to be software installer
please help me...thanks
thanks
|
|
|
|
|
why don't you use an existing installer like InnoSetup, NSIS, InstallShield, etc...?
|
|
|
|
|
thx, but i want to improve my question...
how to make application installer from mfc and opengl.
because i use opengl on my mfc....
|
|
|
|
|
Microsoft have published a set of "lovely" documentation on MSDN to accommodate for setup apps; it's called - rather daringly - the "Setup API" - take a look here.
Hope this helps,
--Perspx
"The Blue Screen of Death, also known as The Blue Screen of Doom, the "Blue Screen of Fun", "Phatul Exception: The WRECKening" and "Windows Vista", is a multi award-winning game first developed in 1995 by Microsoft" - Uncyclopedia
Introduction to Object-Oriented JavaScript
|
|
|
|
|
Install Shield is the one which I use but many alternative exist .
Vikas Amin
UNITED STATES STEEL CORPORATION
My First Article on CP" Virtual Serial Port "[^]
modified on Thursday, July 24, 2008 5:33 PM
|
|
|
|
|
Hi all,
I am facing a strang problem for ImpersonateLoggedOnUser() on Vista 64.
I am having a service and it internally launches a dll and that dll impersonates to paricular domain user. The code works perfect on XP, 2k3, vista 32, XP 64. But on vista 64 the service crashes.
Does anybody have any idea why it might be creashing?
Even i am not able to remote debug it. For remote debugging i put a message box in the dll whenever it pops up i remotely attach to that process and click on the message box for debugging. But on vista i cant see any message box. So how should i remote debug the code on vista 64?
|
|
|
|
|
Hi All
How can i get removable drive letter in MFCvc++2005? Plz give some tips..
|
|
|
|
|
You can use GetLogicalDriveStrings() to get a list of availible drives (documentation here), then for each one use GetDriveType() (documentation here) to determine whether it is a removable drive or not.
Hope this helps,
--Perspx
"The Blue Screen of Death, also known as The Blue Screen of Doom, the "Blue Screen of Fun", "Phatul Exception: The WRECKening" and "Windows Vista", is a multi award-winning game first developed in 1995 by Microsoft" - Uncyclopedia
Introduction to Object-Oriented JavaScript
|
|
|
|
|