|
I am attempting to create a structure that I would like to call sizeof(myStruct) to return 16. However, when I attempt to make this call from code, I get the error,
'myStruct' does not have a predefined size, therefore sizeof can only be used
in an unsafe context (consider using System.Runtime.InteropServices.Marshal.SizeOf) I searched online, and the only note that I found was someone who stated that, because the CLR determines the layout of the structure at runtime, the size of myStruct cannot be determined at compile time. Due to this comment, I thought that I could include the following attribute on my structure to solve this problem:
[StructLayout(LayoutKind.Sequential, Pack = 8, Size = 16)]
public struct myStruct : IEquatable<myStruct>, IComparable<myStruct>, IComparable {
...
} However, this results in the same error. There has to be a way for me to do this, as the built-in types int, float, etc. all allow this method call without throwing an exception. Another issue that I think is related is that I cannot declare a constant of type myStruct. If anyone has some insight into either of these problems, I would appreciate some help. Thanks,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
So use an unsafe context, big deal.
|
|
|
|
|
Ok, but lets say that I am running it within a web service on a server that I don't control, and the server doesn't allow unsafe code to run?
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
In that case what would you do with sizeof?
|
|
|
|
|
I have a collection that I wrote that has a statement at the top as follows:
using BaseType = SomeStructTypeHere;
...
public class Foo : ... {
...
private const int c_Size = sizeof(SomeStructTypeHere) << 3;
private static readonly int c_Bits = MathExtension.Log2(c_Size);
...
} I did this for maintenence purposes, so I could modify the 'Foo' class as necessary to use one of any number of structures as the base type for the class (changing the base type only changes the hard limits on the class, but NOT its functionality). This class is being used in a web service, and therefore cannot use unsafe code, as I have explained. I would now like to use the 'Foo' class with my type as 'BaseType'. How can I go about doing this? Thanks,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
Skippums wrote: cannot use unsafe code, as I have explained
Well, no you hadn't.
I think Mark's question still stands... what are you doing with the size?
|
|
|
|
|
PIEBALDconsult wrote:
Well, no you hadn't [stated that you cannot use unsafe code].
In my second post (in response to Mark), I said,
Ok, but lets say that I am running it within a web service on a
server that I don't control, and the server doesn't allow unsafe code to run? Perhaps I made it sound too much like a hypothetical, but it isn't. It the real-world, so unsafe is out of the question. What exactly am I using it for? Well, basically I need to know the size of the structure (call it 'X', in bits) so I can figure out some shift/mask values as follows:
1. I need to be able to shift something by all values < 'X'
for (byte i = X - 1; i >= 0; --i) {
...
long myValue = someValue << i;
...
}
2. I need to use the mask 'X' - 1 to get information from variables
long myValue = someValue & (X - 1);
3. I need to be able to shift something by log2('X')
long myValue = someValue << MathExtension.Log2(X); The previous three examples are riddled throughout my code, and X, Log2(X), and X-1 are all stored in constants within the class. Those constants are populated by making a call to the sizeof() method on the BaseType struct (declaration: "using BaseType = myStruct;"). How can I get this information without using unsafe context? Thanks,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
We need to know what you are trying to achieve before we can make suggestions. What does this function on the webservice do?
|
|
|
|
|
Iterate the fields and sum their sizes?
Wouldn't you only need the size in an unsafe context anyway?
|
|
|
|
|
Please see my response to Mark for clarification on exactly what I am trying to do. However, iterating over the private members is far too much work for what I am attempting to do. Thanks,
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
say that within each egg carton, the ‘slot’ for each egg is given a number, just like we number arrays. We will also number the egg cartons themselves. So in the picture below, we see that egg carton #0 has 8 slots. Within egg carton #0, the slots are number 0, 1, 2, 3, 4, 5,6, and 7, just like the carton was an array. Another way to number the slots would be to use ‘global slot number’. This is what you’d get, if you started counting at the first slot in the first carton, and then kept counting when you moved on to the second carton, etc, etc. For example, “carton#0, slot#1” would be given the ‘global slot number’ of 1, since you start counting (at carton#0, slot#0) with 0, then count carton#0, slot#1 as ‘global 1’. When you run out space in the first carton (having reached ‘global 7’, at “carton#0, slot#7”), you go on to the second carton, and keep counting. So carton#1, slot#0 is actually ‘global slot number 8’. Carton #1, slot #5 is ‘global slot number 13’, and ‘global slot number 17’ really means carton #2, slot #1.
You need to fill in code, in program that is provided below, so that your program will ask the user for the ‘global slot number’ of a particular slot in a particular egg carton, and will then tell the user which carton, and which slot # with that carton, to put the egg.
|
|
|
|
|
I need to fill in the code?, No i don't. Its not my homework.
Regards,
Gareth.
|
|
|
|
|
Alex501 wrote: your program will ask the user for the ‘global slot number’ of a particular slot in a particular egg carton, and will then tell the user which carton, and which slot # with that carton, to put the egg.
What country is this grocery store in? They don't work like that in the US.
led mike
|
|
|
|
|
Easy. Just limit the number of cartons to 1, and the number of slots in a carton to 1. Then ask for input from user for a global slot number. Reject any input that isn't "1". Then output Carton 1, Slot 1 as your answer.
We violated nature and our children have to pay the penalty
Don't go near the water children... Johnny Cash - 1974
|
|
|
|
|
They don't call you "smart" for nothing.
|
|
|
|
|
When is your homework due? I have five others ahead of you needing "urgent" homework help.
And there is no mention in your help wanted advertisment about how you are going to pay me to do your homework for you.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
|
|
|
|
|
I'm developing a membership app that allows the user to view information in a highly dynamic way. For instance the user can click through folder like structures, add/edit/move/delete records. Right now I'm saving the data to an Access database and I'm fine with that. My concern is that with the methods I've established, this dynamic interface will require a lot of table creation. I need answers to the following questions:
1. Does excessive amounts of tables slow the performance of an Access db or does only the amount a records slow the performance.
2. Is there a better way to save my data? I am wanting to write the code so it can adapt to a multi-user program.
Thanks a million!
Richard
may your code be error free.
(okay, maybe two lines.)
|
|
|
|
|
programmingAddict wrote: Right now I'm saving the data to an Access database
programmingAddict wrote: so it can adapt to a multi-user program.
I don't believe Access is recommended for multi-user systems. But since your data is highly dynamic that could be a special case. My experience is limited to data that is sort of dynamic.
led mike
|
|
|
|
|
You need to live a little. I've seen data so dynamic that it blurs when you save it to the database.
Of course its a pain to debug because the exceptions can fly right past your eyeballs, and the sonic boom can spilt coffee mugs at ten paces.
I'm terrible at debugging without coffee
|
|
|
|
|
Richard,
I've had a million rows in some Access databases, no problem.
I'm trying to understand why you are creating tables on the fly.
What sort of data are you saving?
Can you define a set number of tables and use your UI to populate those tables?
How many members are we talking about?
modified 27-Feb-21 21:01pm.
|
|
|
|
|
The reason I want to allow the user to create their own data structures (in addition to the ones that have already been created) is because it would give the user so much more flexibility. In addition I want to create a interface that allows the user to organize the data in the way they best relate to. The Windows File/Folder system is the best example. I could do a conventional file system but I don't think that will work in multi-user enviroment. Can you see my dilemma?!
may your code be error free.
(okay, maybe two lines.)
|
|
|
|
|
Ok, now I see where you are going.
I've done this before with XML structures. You "could" serialize the XML data to a single record as a binary stream for that customer. Access supports this, along with SQL Server. You application will determine if each customer needs one or more records to handle the features you need. But this should be easy to figure out.
Using an XML data structure allows for free data structure that can be dynamic.
Depending on your search requirements you may want to index some or all of the data. Without knowing all the pieces I can't advise with authority.
Have you thought about SQL Server Express. It's free, multi user and FAST.
Hope this helps, time for bed.
modified 27-Feb-21 21:01pm.
|
|
|
|
|
programmingAddict wrote: because it would give the user so much more flexibility.
Do you have a specific User community so that you know this is a good idea?
Most users would just hang themselves with the flexibility. I mean many software developers are not capable of designing schemas properly, what makes you think you want to delegate that responsibility to users?
programmingAddict wrote: I could do a conventional file system but I don't think that will work in multi-user enviroment.
I'm pretty sure it works for Sharepoint
led mike
|
|
|
|
|
I understand your point but Microsoft allows their users to organize music/videos/documents/folders like they want to.
Okay, lets say I was creating a photo organizer app. How would a developer design a muti-user application that allows the users to create/edit/organize their photo collections. For instance, what if the user with administrative privileges would want to create a folder that stores all photo's of his aunt's vacation to the Bahammas. He would probably want to name it: Aunts Trip To Bahammas.
No predefined template can acommodate all these variables.
Thanks for all the input so far!
may your code be error free.
(okay, maybe two lines.)
|
|
|
|
|
Hi all,
Any one please suggest me how to call a javascript function inside a asp:hyperlinkcolumn column. I want to call a javascript function when a user click the asp:hyper link text. In html link we can do tht using onclick function, is there any option like this in asp:hyperlink?
Also i need one more suggestion, plz suggest me some web sites from where i can learn Hibernate using .NET with some basic samples.
Thanks in advance
Know is Drop, Unknown is Ocean
|
|
|
|
|