I read Cwalina book (recommendations on development and design of .NET apps).
He says that good designed struct has to be less than 16 bytes in size (for performance purpose).
My questions is - why exactly is this?
And (more important) can I have larger struct with same efficiency if I run my .NET 3.5 (soon to be .NET 4.0) 64-bit ap...
Does anyone know the answer and/or have an oppinion about it?
Since tuples would normally not be very large I would assume it would make more sense to use structs than classes for these. What say you?
...
For some reason I keep getting segmentation fault when I try to get the size of my struct.
struct my_struct {
char *a;
int b;
};
int main(int argc, char *argv[])
{
struct my_struct dastruct;
size_t len = sizeof(dastruct) / sizeof(struct my_struct); // error
qsort(dastruct, len, sizeof(struct my_struct), cmp);
...
}...
Ultimately I want to determine if the machine my program is running on is a laptop or desktop. I'd like to do this with JNA and msn's PowrProf lib, GetPwrCapabilities Function using the LidPresent flag.
Part of the SYSTEM_POWER_CAPABILITIES struct (which is the argument for the GetPwrCapabilities method)
BYTE spare...
I am back into c/Linux. The question might look stupid, but relevant after working in c# etc.
I have some structures inside structures and the hierarchy level is more than 5. In such a case, I am doing an initialisation of every structure at the beginning explicitly. I know c does not have a new() method that will do it for you. Now I w...
I'm trying to test if a property has been set yet. I know that with objects that I've got:
CGRect ppGoalFrame;
LocalPlaySetup *localPlaySetup;
and I can test
if (localPlaySetup == nil)
but if I attempt to test the CGRect with == nil or == NULL
if (ppGoalFrame == nil)
I get
invalid operands to binary == (have 'CGRect' and 'void...
I am working on a program in C and using the SDCC compiler for a 8051 architecture device.
I am trying to write a function called GetName that will read 8 characters from Flash Memory and return the character array in some form. I know that it is not possible to return an array in C so I am trying to do it using a struct like this:
//*...
For some reason if I try to get the actual size of mystruct I keep getting size 1.
I know that mystruct is holding the data cause I can dump it out and everything is in mystruct.
What could be the reason of getting size 1?
Thanks
// fragments of my code
struct mystruct {
char *raw;
int count;
};
struct counter {
int tot...
My problem is very simple. My problem is to send a structure between a program in C to a C# program.
I made a struct in C#:
public struct NetPoint {
public float lat; // 4 bytes
public float lon; // 4 bytes
public int alt; // 4 bytes
public long time; // 8 bytes
}
Total size of the struct must be 20 bytes.
When I do...
Hi I am trying to use C to implement a simple struct:
2 boxes, each contains different number of particles; the exact number of particles are passed in main().
I wrote the following code:
typedef struct Particle{
float x;
float y;
float vx;
float vy;
}Particle;
typedef struct Box{
Particle p[];
}Box;
void make_box...
I'm reading some C code like that:
double function( int lena,double xa,double ya, double za, double *acoefs, ...,
int lenb,double xb,double yb, double zb, double *bcoefs, ...,
same for c,
same for d )
This function is called in the code mor than 100.000 times so it's performance-criti...
Hi,
How would you locate an object in memory, lets say that you have a struct defined as:
struct POINT {
int x;
int y;
};
How would I scan the memory region of my app to find instances of this struct so that I can read them out?
Thanks R.
...
In my app, I'm storing Bitmap data in a two-dimensional integer array (int[,]). To access the R, G and B values I use something like this:
// read:
int i = _data[x, y];
byte B = (byte)(i >> 0);
byte G = (byte)(i >> 8);
byte R = (byte)(i >> 16);
// write:
_data[x, y] = BitConverter.ToInt32(new byte[] { B, G, R, 0 }, 0);
I'm using inte...
Hi
I am using ms c++. I am using struct like
struct header {
unsigned port : 16;
unsigned destport : 16;
unsigned not_used : 7;
unsigned packet_length : 9;
};
struct header HR;
here this value of header i need to put in separate char array.
i did memcpy(&REQUEST[0], &HR, sizeof(H...
I'm playing around with templates. I'm not trying to reinvent the std::vector, I'm trying to get a grasp of templateting in C++.
Can I do the following?
template <typename T>
typedef struct{
size_t x;
T *ary;
}array;
What I'm trying to do is a basic templated version of:
typedef struct{
size_t x;
int *ary;
}iArray;
It look...
I have quite a few dictionaries where the key is a composite of several different values (mostly strings and integers). Do I implement these keys as classes (and override GetHashCode(), Equals() etc) or do I use struct instead?
ReSharper makes it easy to do the overriding, but the code looks horrible. Are there any performance implicat...
I am working on understanding Core Audio, or rather: Extended Audio File Services
Here, I want to use ExtAudioFileRead() to read some audio data from a file.
This works fine as long as I use one single huge buffer to store my audio data (that is, one AudioBuffer). As soon as I use more than one AudioBuffer, ExtAudioFileRead() returns th...
struct struct0 {
int a;
};
struct struct1 {
struct struct0 structure0;
int b;
} rho;
&rho->structure0; /* Reference 1 */
(struct struct0 *)rho; /* Reference 2 */
(struct struct0)rho; /* Reference 3 */
From reference 1, does the compiler take the address of rho, and then access structure0, or vice-versa?
What does the line at ...
I showed this struct to a fellow programmer and they felt that it should be a mutable class. They felt it is inconvenient not to have null references and the ability to alter the object as required. I would really like to know if there are any other reasons to make this a mutable class.
[Serializable]
public struct PhoneNumber : IEquata...
I've been using the following code to create various struct, but only give people outside of the C file a pointer to it. (Yes, I know that they could potentially mess around with it, so it's not entirely like the private keyword in Java, but that's okay with me).
Anyway, I've been using the following code, and I looked at it today, and...