473,387 Members | 1,876 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,387 software developers and data experts.

Some C++ functionality not available in C# [???]

Hi,

[A]. I am using managed code ( C# )
[b]. I am working on a performance critical application that involve 3D
Graphics.
[C]. To achieve optimal performance I try to copy data as less as possible.
[D]. The view port is represented by a 3D Vector ( or DirectX.Vector3 )
[E]. The coordinates of this vector vary and are calculated on runtime by
combination of Euler matrix transformations.
[F]. Getting the Translation ( position ) of the view port from the Matrix
require me to copy the XYZ coordinates each time a frame is drawn.
[G]. Using C++ it is NOT need to copy the Translation coordinates
( The following sample shows how ).

Following is a C++ sample for achieving what was just
described ( what is the C# equivalent [???] )
struct Vector
{
float X;
float Y;
float Z;
};

struct Matrix
{
public:
float M11;
float M12;
float M13;
Nov 16 '05 #1
6 1107
Yeah, with the unsafe mode of C#, you can use pointers and pin down memory
locations; which should give you many of the possibilities of C++ (but not
necessarily with the same syntaxe). However, in your case, you should use
C++ Managed instead if you want to make heavy use of pointers.

S. L.

"Nadav" <Na***@discussions.microsoft.com> wrote in message
news:CD**********************************@microsof t.com...
Hi,

[A]. I am using managed code ( C# )
[b]. I am working on a performance critical application that involve 3D
Graphics.
[C]. To achieve optimal performance I try to copy data as less as
possible.
[D]. The view port is represented by a 3D Vector ( or DirectX.Vector3 )
[E]. The coordinates of this vector vary and are calculated on runtime by
combination of Euler matrix transformations.
[F]. Getting the Translation ( position ) of the view port from the Matrix
require me to copy the XYZ coordinates each time a frame is drawn.
[G]. Using C++ it is NOT need to copy the Translation coordinates
( The following sample shows how ).

Following is a C++ sample for achieving what was just
described ( what is the C# equivalent [???] )
struct Vector
{
float X;
float Y;
float Z;
};

struct Matrix
{
public:
float M11;
float M12;
float M13;
.
.
.
float M41; // X Translation
float M42; // Y Translation
float M43; // Z Translation
float M44;

float &X;
float &Y;
float &Z;

inline operator Vector*() { return static_cast<Vector*>(&X); }

Matrix() : X(M41), Y(M42), Z(M43) {}
};

I am using managed code (C#), is it possible to achive the same
Vector/Matrix association using managed code???? How?

Thanks,
Nadav
nadavrub A T gmail D O T com

Nov 16 '05 #2
Also, I'm not really sure about the performance hit of copying some data
here and there in comparaison of the number of CPU cycles it takes to apply
mathematical operations on them.

Before working on the ultimate performance, you should first work on
finishing your product; then, if you have some performance issues, you ask
your clients to wait one week or two before buying their next computer. The
more powerfull CPU that they will get by waiting a few weeks will more than
compensate for the small performance hit.

S. L.

"Sylvain Lafontaine" <sylvain aei ca (fill the blanks, no spam please)>
wrote in message news:uD**************@TK2MSFTNGP14.phx.gbl...
Yeah, with the unsafe mode of C#, you can use pointers and pin down memory
locations; which should give you many of the possibilities of C++ (but not
necessarily with the same syntaxe). However, in your case, you should use
C++ Managed instead if you want to make heavy use of pointers.

S. L.

"Nadav" <Na***@discussions.microsoft.com> wrote in message
news:CD**********************************@microsof t.com...
Hi,

[A]. I am using managed code ( C# )
[b]. I am working on a performance critical application that involve 3D
Graphics.
[C]. To achieve optimal performance I try to copy data as less as
possible.
[D]. The view port is represented by a 3D Vector ( or DirectX.Vector3 )
[E]. The coordinates of this vector vary and are calculated on runtime by
combination of Euler matrix transformations.
[F]. Getting the Translation ( position ) of the view port from the
Matrix
require me to copy the XYZ coordinates each time a frame is drawn.
[G]. Using C++ it is NOT need to copy the Translation coordinates
( The following sample shows how ).

Following is a C++ sample for achieving what was just
described ( what is the C# equivalent [???] )
struct Vector
{
float X;
float Y;
float Z;
};

struct Matrix
{
public:
float M11;
float M12;
float M13;
.
.
.
float M41; // X Translation
float M42; // Y Translation
float M43; // Z Translation
float M44;

float &X;
float &Y;
float &Z;

inline operator Vector*() { return static_cast<Vector*>(&X); }

Matrix() : X(M41), Y(M42), Z(M43) {}
};

I am using managed code (C#), is it possible to achive the same
Vector/Matrix association using managed code???? How?

Thanks,
Nadav
nadavrub A T gmail D O T com


Nov 16 '05 #3
I didn't know that people would go to such levels to avoid copying...
Heck you should be programming in assembler, not C++. You're defeating
the type system in the worst possible way. Your code looks extremely
fragile to me, it's going to crash at runtime if Vector changes and
someone forgets to change Matrix..

Anyway, in .NET, the following code
class Vector
{
....
}
void GetVector()
{
return new Vector(x,y,z);
}

returns a reference to hte created vector and not a copy. It's like
returning a reference in C++. I think that's what you're trying to
avoid.

Regards
Senthil

Nov 16 '05 #4
Well, You hit the point, this exactly what i am trying to achieve, variables
M41, M42, M43 of the matrix ) represent the translation of a point in 3D
space, the same variables can be used to describe the same point using a
Vector, referring bought of the types to the same memory address will save
the burden of making sure the vector is updated each time the matrix change
and vide-versa...

"sadhu" wrote:
I didn't know that people would go to such levels to avoid copying...
Heck you should be programming in assembler, not C++. You're defeating
the type system in the worst possible way. Your code looks extremely
fragile to me, it's going to crash at runtime if Vector changes and
someone forgets to change Matrix..

Anyway, in .NET, the following code
class Vector
{
....
}
void GetVector()
{
return new Vector(x,y,z);
}

returns a reference to hte created vector and not a copy. It's like
returning a reference in C++. I think that's what you're trying to
avoid.

Regards
Senthil

Nov 16 '05 #5
Well ,Indeed, usage of managed C++/unsafe C# may resolve the problem just
described BUT concerning usage of 'Vector*' is required at a scope external
to the method ( where the matrix memory is pinned ) it may point to an
invalid memory address ( resulting of GC memory compacting )... I guess
managed code (whether safe or unsafe) doesn't support this kind of
functionality... It would be nice if it would be added in future versions of
the .NET framework...

"Sylvain Lafontaine" wrote:
Yeah, with the unsafe mode of C#, you can use pointers and pin down memory
locations; which should give you many of the possibilities of C++ (but not
necessarily with the same syntaxe). However, in your case, you should use
C++ Managed instead if you want to make heavy use of pointers.

S. L.

"Nadav" <Na***@discussions.microsoft.com> wrote in message
news:CD**********************************@microsof t.com...
Hi,

[A]. I am using managed code ( C# )
[b]. I am working on a performance critical application that involve 3D
Graphics.
[C]. To achieve optimal performance I try to copy data as less as
possible.
[D]. The view port is represented by a 3D Vector ( or DirectX.Vector3 )
[E]. The coordinates of this vector vary and are calculated on runtime by
combination of Euler matrix transformations.
[F]. Getting the Translation ( position ) of the view port from the Matrix
require me to copy the XYZ coordinates each time a frame is drawn.
[G]. Using C++ it is NOT need to copy the Translation coordinates
( The following sample shows how ).

Following is a C++ sample for achieving what was just
described ( what is the C# equivalent [???] )
struct Vector
{
float X;
float Y;
float Z;
};

struct Matrix
{
public:
float M11;
float M12;
float M13;
.
.
.
float M41; // X Translation
float M42; // Y Translation
float M43; // Z Translation
float M44;

float &X;
float &Y;
float &Z;

inline operator Vector*() { return static_cast<Vector*>(&X); }

Matrix() : X(M41), Y(M42), Z(M43) {}
};

I am using managed code (C#), is it possible to achive the same
Vector/Matrix association using managed code???? How?

Thanks,
Nadav
nadavrub A T gmail D O T com


Nov 16 '05 #6
Pinned managed memory and unmanaged memory (memory directly allocated by
C++) won't be affected by the GC. Of course, Vector* must be allocated on
the heap and not on the stack.

S. L.

"Nadav" <Na***@discussions.microsoft.com> wrote in message
news:BA**********************************@microsof t.com...
Well ,Indeed, usage of managed C++/unsafe C# may resolve the problem just
described BUT concerning usage of 'Vector*' is required at a scope
external
to the method ( where the matrix memory is pinned ) it may point to an
invalid memory address ( resulting of GC memory compacting )... I guess
managed code (whether safe or unsafe) doesn't support this kind of
functionality... It would be nice if it would be added in future versions
of
the .NET framework...

"Sylvain Lafontaine" wrote:
Yeah, with the unsafe mode of C#, you can use pointers and pin down
memory
locations; which should give you many of the possibilities of C++ (but
not
necessarily with the same syntaxe). However, in your case, you should
use
C++ Managed instead if you want to make heavy use of pointers.

S. L.

"Nadav" <Na***@discussions.microsoft.com> wrote in message
news:CD**********************************@microsof t.com...
> Hi,
>
> [A]. I am using managed code ( C# )
> [b]. I am working on a performance critical application that involve 3D
> Graphics.
> [C]. To achieve optimal performance I try to copy data as less as
> possible.
> [D]. The view port is represented by a 3D Vector ( or DirectX.Vector3 )
> [E]. The coordinates of this vector vary and are calculated on runtime
> by
> combination of Euler matrix transformations.
> [F]. Getting the Translation ( position ) of the view port from the
> Matrix
> require me to copy the XYZ coordinates each time a frame is drawn.
> [G]. Using C++ it is NOT need to copy the Translation coordinates
> ( The following sample shows how ).
>
> Following is a C++ sample for achieving what was just
> described ( what is the C# equivalent [???] )
> struct Vector
> {
> float X;
> float Y;
> float Z;
> };
>
> struct Matrix
> {
> public:
> float M11;
> float M12;
> float M13;
> .
> .
> .
> float M41; // X Translation
> float M42; // Y Translation
> float M43; // Z Translation
> float M44;
>
> float &X;
> float &Y;
> float &Z;
>
> inline operator Vector*() { return static_cast<Vector*>(&X); }
>
> Matrix() : X(M41), Y(M42), Z(M43) {}
> };
>
> I am using managed code (C#), is it possible to achive the same
> Vector/Matrix association using managed code???? How?
>
> Thanks,
> Nadav
> nadavrub A T gmail D O T com


Nov 16 '05 #7

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

Similar topics

9
by: Edilmar | last post by:
Hi, First of all, I'm new in Python... I have worked with manu langs and IDEs, like Delphi, VB, JBuilder, Eclipse, Borland C++, Perl, etc... Then, today I think IDEs like Delphi have a...
0
by: Remy Blank | last post by:
Ok, here we go. I added the possibility for tests using the unittest.py framework to be skipped. Basically, I added two methods to TestCase: TestCase.skip(msg): skips unconditionally...
6
by: futurepy | last post by:
Hello, I am not good at JS at all. If you are reading this message with the IE, please move the cursor up to the top of the page. When the cursor stops at an icon, a rectangle slot will...
4
by: Marquisha | last post by:
If this is off-topic, please forgive me. But I thought this might be the perfect spot to get some advice about how to proceed with a project. Working on a Web site design for a nonprofit...
193
by: Michael B. | last post by:
I was just thinking about this, specifically wondering if there's any features that the C specification currently lacks, and which may be included in some future standardization. Of course, I...
1
by: Shawn | last post by:
Hi All; another simpleton question. i'm pretty sure i already know but... what is a .Net Assembly? In the C++ app i work on at work, we use a main app with COM "plugnis" and a few COM servers....
4
by: msnews.microsoft.com | last post by:
I have a VB.NET web application using SQL Server. I need to do weekly and monthly processing on that database that will probably require a couple hours to complete, so having this run in the web...
6
by: maheswaran | last post by:
I need FTP with the following functionality. 1. A FTP tool, which will automatically send email to people once download/upload is over. Is there any ftp available with this functionality?.
4
by: maheswaran | last post by:
I need FTP with the following functionality. 1. A FTP tool, which will automatically send email to people once download/upload is over. Is there any open source ftp available with this...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.