473,386 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Enforce declaration of values (C# 2.0)

Hi I have some "unusual" problem ^^

Is there an way to enforce the declaration of values?
If the answer is no use propertys can anyone tell me how to access a
construct like this over properties.
Access should be easy like
....some code
Memory m;
....some code
byte v = m.complete[22];
....some code

[StructLayout(LayoutKind.Explicit, Size = 20)]
public unsafe struct Memory
{
[FieldOffset(0)]
public fixed byte complete[20];
[FieldOffset(0)]
public fixed sbyte signedcompete[20];
}

The topic for the solution is "Get fastes possible access in C#"

Thanks
Michael
Mar 27 '06 #1
2 3326
Hi,

I did not understand nothing from your post, would you mind to elaborate
further?
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Michael Schöller" <sw****@yahoo.com> wrote in message
news:eu**************@TK2MSFTNGP10.phx.gbl...
Hi I have some "unusual" problem ^^

Is there an way to enforce the declaration of values?
If the answer is no use propertys can anyone tell me how to access a
construct like this over properties.
Access should be easy like
...some code
Memory m;
...some code
byte v = m.complete[22];
...some code

[StructLayout(LayoutKind.Explicit, Size = 20)]
public unsafe struct Memory
{
[FieldOffset(0)]
public fixed byte complete[20];
[FieldOffset(0)]
public fixed sbyte signedcompete[20];
}

The topic for the solution is "Get fastes possible access in C#"

Thanks
Michael

Mar 27 '06 #2
What I try to do is create an replaceable library that contains the struct
"Memory".
I want to acces that sruct over an interface so that someone who figures out
an faster way (performance is important) can write an alternative library
based on the interface.
The programm itself emulates an 8bit microprocessor with an reduced
instruction set (64 OP codes). The programm should be as fast as possible to
keep testtime short. To use C# 2.0 for the programm was choosen by
management so switching to C++ is not an option.
The struct itself repesents the memory of the microprocessor, some of the OP
codes uses math operations that expect unsigned bytes an some expect signed
bytes. There are also some special memory locations that should be
accessable with special names like the Flagregister that is located in the
last byte of the memory (already found a solution that work with interfaces
over properties, unfortunaly this soloution seems not to work for arrays).
As you see the struct is very special in that way that the array are share
the same memory one is sbyte the other byte what grants fast access both
ways.
Also the example I had given is very simplyfied the original Memory-object
also has special adress ranges that would look like
[StructLayout(LayoutKind.Explicit, Size = 20)]
public unsafe struct Memory
{
[FieldOffset(0)]
public fixed byte complete[20];
[FieldOffset(0)]
public fixed sbyte signedcompete[20];
[FieldOffset(5)]
public fixed byte pathcontrol[5];
}
If I would use properties to create the same effect I would have to copy the
datas in the set and get statement while converting them if needed The
property of pathcontrol the normal way would be a simple
complete.CopyTo(...) and vice versa but thats the slowest possible solution.
The example i had given is much faster.

Now there should be the posibillity to excange the library that contains
this special struct, lets say with an code that do not need unsafe and fixed
statements without changing the rest of the application. Normaly I would
define an interface that enables access to the memory object but I have no
idea how to access the arraysover an interface by using properties without
copy the arrays to an temorary byte[] object.
What I am looking for is an solution that may use properties or whatever,
but do not need to make temporary copys of the arrays in the struct.

At first I was thinking about an construct like (I know that this code is
not working it's just "dreamcode [<-to good to be true]")
StructLayout(LayoutKind.Explicit, Size = 20)]
public unsafe struct Memory : IMOMCMemory
{
[FieldOffset(0)]
private fixed byte complete[20];

public byte CompleteMemory[int index] //Interfaceimplementation.
{
get{ return complete[index]; }
set { complete[index] = value; }
}
}
Something like that, so that I can get an easy access to the arrays.
Indexers would be an idea but I would need more than one (signed/unsigned
access to the whole memory and parts of it) and since there would only be
one parameter "int index" thery would be not well definded.

I hope that makes it clear

Michael

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us>
schrieb im Newsbeitrag news:uu**************@TK2MSFTNGP09.phx.gbl...
Hi,

I did not understand nothing from your post, would you mind to elaborate
further?
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Michael Schöller" <sw****@yahoo.com> wrote in message
news:eu**************@TK2MSFTNGP10.phx.gbl...
Hi I have some "unusual" problem ^^

Is there an way to enforce the declaration of values?
If the answer is no use propertys can anyone tell me how to access a
construct like this over properties.
Access should be easy like
...some code
Memory m;
...some code
byte v = m.complete[22];
...some code

[StructLayout(LayoutKind.Explicit, Size = 20)]
public unsafe struct Memory
{
[FieldOffset(0)]
public fixed byte complete[20];
[FieldOffset(0)]
public fixed sbyte signedcompete[20];
}

The topic for the solution is "Get fastes possible access in C#"

Thanks
Michael


Mar 27 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: gino | last post by:
Dear all, My monitor was set to 1600x1200 so the fonts in IE is too small for me even when I set the "View->Text Size->Largest"... I don't have previlage to change the monitor resolution... ...
1
by: shumaker | last post by:
....please. I've found other posts that explain the Cascade options, but the Enforce relationships option still is foggy to me. As to "enforcing relationship for ... UPDATEs"(with cascade NOT...
4
by: Ray Dukes | last post by:
What I am looking to do is map the implementation of interface properties and functions to an inherited method of the base class. Please see below. ...
14
by: Sacha Schär | last post by:
Hi there, i have a sequence like the following: const char *a = "foo"; char b; for ( i = 1; i < strlen(a); i++) { b = a;
28
by: Larax | last post by:
Best explanation of my question will be an example, look below at this simple function: function SetEventHandler(element) { // some operations on element element.onclick = function(event) {
2
by: =?Utf-8?B?Qw==?= | last post by:
Hi, I have an asp.net textbox and I want to enforce that the user inputs values in the following format 1498159\102 How can I do this using a Regular Expression or otherwise? Any advice...
2
by: elmar_macek | last post by:
Hi all, i have recently stumbled about a problem: I have implemented a class GeneraBucket, which is superclass for Bucket and PBucket. I need a method in PBucket that returns a pointer to a...
7
mickey0
by: mickey0 | last post by:
hello, I wrote this but it doens't compile; more or less I see the error; I have to include "pattern.h" instead of "class Pattern" in patternset.h; But I don't understand why: This is the error: ...
2
by: Christopher | last post by:
If I have an generic interface, but _also_ have the implementation for it and want to use that common implementation in my derived classes, what method does that leave me to make pure virtual such...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.