|
If you substitute 'class' for 'struct' it will be an array of pointers. Classes are implemented as pointers to the data in the heap.
|
|
|
|
|
Alan Balkany wrote: I suspect the array of structs is five 14-byte structures that follow each other in memory.
Actually it's five 16-byte structures that follow each other in memory. The members in the struct are padded to the next word boundary, so there is two unused bytes after the ushort.
Alan Balkany wrote: But if a class is used, I suspect the array is five 4-byte pointers to RoomDef objects allocated in the heap.
The array is five references (4 or 8 bytes depending on the platform), however no RoomDef objects are created to populate the array when the array is created. All the references are null from start.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks for the clarifications, Guffa.
|
|
|
|
|
I noticed an interesting quirk in C#: You can only use the sizeof() operator on a struct if it only contains value types. Replacing the three string members in RoomDef with ushort allows sizeof() to be used on the struct.
|
|
|
|
|
Alan Balkany wrote: I think you can have a pointer to a value type.
Yes, you can, but the variable we are talking about is not a pointer.
Alan Balkany wrote: When you make a struct with 'new' I think it's allocated in the heap.
No, it's not. The constructor only creates the value, it's not allocated anywhere. In this case the value is then assigned to the local variable.
Alan Balkany wrote: I think structs are only put on the stack when they're local variables.
It is a local variable.
Besides, a struct is never allocated on the heap by itself. A struct can be a part of a class that is allocated on the heap, it can be part of an array that is allocated on the heap, or it can be boxed inside an object that is allocated on the heap, but never on it's own.
Despite everything, the person most likely to be fooling you next is yourself.
modified on Wednesday, September 17, 2008 2:55 PM
|
|
|
|
|
You should use a class instead of a structure, so that you can allocate instances of it that will survive the local scope.
If you would have succeeded in putting the pointer in the array, it would be a pointer to the structure allocated in the stack frame of the method. When you return from the method, the structure doesn't exist any more, so the pointer is no longer valid.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks for the Reply,
Will c heck as a class, but then any idea why it gives me an compile error when i do it this way?
|
|
|
|
|
Preetham.N wrote: any idea why it gives me an compile error
Which compile error?
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Have tried using a class , no luck
|
|
|
|
|
Thanks Guys
Changed it to Class. Works
|
|
|
|
|
I am developing ASP.Net Applciation.I have a requirement to store the data into Application object whose data rarely changes.So the Application Object should be refershed with the Updated data once in a day.For that How to Set Expiration Policy to an Application Object in ASP.Net Applciation?
|
|
|
|
|
Keep a timestamp with the object. Whenever you access object, check this timestamp and reload it when necessary. I think you can use cache with your expiry time. So runtime manages it automatically.
BhanuRegonda wrote: I am developing ASP.Net Applciation.
BTW, you are in wrong forum. You could try ASP.NET forum.
|
|
|
|
|
I am trying to create a control that displays a type of threshold.
I have 3 numeric up down controls that take an input from the user. Depending on the input I update the below control. The control is made up of 3 blocks of colour. Each block represents a numeric up down value.
_______________
| y | o | r |
_______________
(y = yellow, o = orange, r = red)
So for instance, yellow is 5, orange is 8 and red is 10. I then need to update the size of the blocks to represent them.
This would then display the blocks correctly, so that 0 - 50% of the control is yellow, 50 to 80% is orange and the last 80 to 100% is red. However, these are only example values, the values could be anything and not in order, eg: 10, 5, 20
Does anyone know how to do this?, I am sure there is a simple maths way, but I cannot think of it at the moment.
Regards,
Gareth.
(FKA gareth111)
|
|
|
|
|
Can you please clarify one of my question.If we are trying incerese any value for any of the block,does it need to impact the sizes of respective blocks or are they fixed with the 0-50% Yellow,50-80% Red,etc.,?
|
|
|
|
|
No, the blocks change depending on the value entered by the user from the numeric up down. I just used the 0 - 50% etc as an example.
Regards,
Gareth.
(FKA gareth111)
|
|
|
|
|
In the control's Paint-event handler:
1. Get the sum of the three controls. In your example sum = 5 + 8 + 10 = 23.
2. Get the percentage of the total for each color: yp = 5 / 23, etc...
3. Get the bounds of your YOR control: (x, y) Location, Width, and Height.
4. Draw the three colors:
a) Draw a solid yellow rectangle at (x, y), yp * Width, Height
b) Draw a solid orange rectangle at (x + yp * Width, y), op * Width, Height.
c) Draw a solid red rectangle at (x * yp * Width + op * Width), rp * Width, Height.
|
|
|
|
|
Alan,
I tried what you suggested, but i cannot see colours on the screen.
decimal total = yellow + orange + red;<br />
decimal yellowPerc = yellow / total;<br />
decimal orangePerc = orange / total;<br />
decimal redPerc = red / total;<br />
<br />
int width = 150;<br />
int height = 20;<br />
<br />
int x = 20;<br />
int y = 20;<br />
<br />
Size yellowSize = new Size((int)orangePerc * width, height);<br />
Rectangle yellowRectangle = new Rectangle(new Point(x, y), yellowSize);<br />
<br />
Size orangeSize = new Size((int)orangePerc * width, height);<br />
Point orangePoint = new Point(x + (int)orangePerc * width, y);<br />
Rectangle orangeRectangle = new Rectangle(orangePoint, orangeSize);<br />
<br />
Size redSize = new Size((int)redPerc * width, height);<br />
Point redPoint = new Point(x * (int)yellowPerc * width + (int)orangePerc * width, y);<br />
Rectangle redRectangle = new Rectangle(redPoint, redSize);
Thats the code i have used, minus the actual drawing.
Regards,
Gareth.
(FKA gareth111)
|
|
|
|
|
A guess: The percentage variables (e.g. orangePerc) are between 0 and 1. When you cast them to int, they're truncated to zero. Did you look at these values in a debugger? (That should be your first reaction when code doesn't work.)
|
|
|
|
|
Alan,
Ye, I had a look in my trace statements and the percentages were zero. So I changed my code to cast the percentages to int's in the Size/Point constructors. eg:
Size yellowSize = new Size((int)(orangePerc * width), height);<br />
Rectangle yellowRectangle = new Rectangle(new Point(x, y), yellowSize);<br />
<br />
Size orangeSize = new Size((int)(orangePerc * width), height);<br />
Point orangePoint = new Point((int)(x + orangePerc * width), y);<br />
Rectangle orangeRectangle = new Rectangle(orangePoint, orangeSize);<br />
<br />
Size redSize = new Size((int)(redPerc * width), height);<br />
Point redPoint = new Point((int)(x * yellowPerc * width + orangePerc * width), y);<br />
Rectangle redRectangle = new Rectangle(redPoint, redSize);
The yellow and orange block were displayed but not red, but were the same size.
I am not 100% sure you have understood want I want, as I do not want proportions - which from the perc * width, it looks like that's what you think I want.
It should be like a ruler. I think that's the best way of explaining it. So, the ruler is 10 long (red == 10), and you have sections of yellow (5) and orange (8).
Hope that helps.
Regards,
Gareth.
(FKA gareth111)
|
|
|
|
|
You should know how to set a breakpoint (F9) and step through your code in the debugger (F5 to run to the next breakpoint, F10 to single-step, and F11 to step into a function call.)
Since you're getting some output now and know the most important debugger commands, you should be able to take it from here. Good luck.
|
|
|
|
|
Hello
What is the best for creating a log?
Is it the tracelistener or ....
best regards
dghdfghdfghdfghdgh
|
|
|
|
|
ellllllllie wrote: Hello
What is the best for creating a log?
Is it the tracelistener or ....
Are you in a hurry?
|
|
|
|
|
ellllllllie wrote: What is the best for creating a log?
An axe and a tree usually.
ellllllllie wrote: Is it the tracelistener or ....
My personal preference is log4net - It's an open source logging component.
Additional:
Oohh! A 1-vote - Someone obviously can't read smilies or simply has zero sense of humour.
modified on Wednesday, September 17, 2008 8:16 AM
|
|
|
|
|
Colin Angus Mackay wrote: or simply has zero sense of humour.
or just wants codeZ
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
you.suck = (you.Passion != Programming & you.Occupation == jobTitles.Programmer)
1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111
|
|
|
|
|
hi,
to create a log book (monitor login/logout & user actions) you need to store data, so you need to build a database.
one like this structure:
myUsers
id,F_name,L_name,...whatever
myLogTable1
id,id_user,date_login,date_logout
2,34,2-3-2007 20:30:23,2-3-2007 21:40:43
...
(login procedure edit; id,id_user,date_login
logout procedure edit; date_logout)
myLogTable2
id,date,user,action
34,3-8-2005 10-2-2004 10:23:34,add sale
45,3-8-2005 11-2-2004 10:33:14,delete client
...
or you can find a way to put 2 tables together.
(go to sql forum next time you need help on this subject)
nelsonpaixao@yahoo.com.br
trying to help & get help
|
|
|
|
|