Jump to content

  • Log In with Google      Sign In   
  • Create Account


ATC

Member Since 07 Oct 2010
Offline Last Active Jan 12 2013 11:13 PM

Topics I've Started

The Singleton Pattern: To be or not to be [used]?

07 November 2012 - 06:25 AM

I'm aware of the numerous problems that can arise through the use of the Singleton pattern, which some go as far as calling an anti-pattern... One of the biggest problems is all the references to the global instance/state, for example:

[source lang="csharp"]// inside method body...var obj = Something.Get();obj.TakeAction();obj.Whatever();[/source]

This can really complicate testing and make code that's difficult to maintain...

However, I'm wondering if the Singleton pattern is not ok (or even optimal) for certain circumstances when only one, globally accessible instance of something should exist...

Consider the class I'm currently working on. It is called "NativeMemoryManager", and it is essentially a "safe" API for allocating, manipulating and releasing unmanaged process memory within a .NET application (it uses a 1:1 wrapper I wrote of the CRT memory management API as its back-end -- this is all part of my generalized application & game development framework). NativeMemoryManager inherits "DisposableObject", which is an abstract class that offers a robust implementation of the IDisposable interface; all instances of which are pushed into the "ObjectTable" which is traversed at application shutdown to destroy potential memory leaks...

Only one instance of NativeMemoryManager should ever exist. It's only field is a data table which stores critical information about all memory allocations to prevent memory errors and free any unfreed memory when the application is shutdown. It doesn't need multiple states, and I don't foresee myself ever wanting to replace the singleton instance with some sort of testing instance. Also, if I implement any objects which need to use/consume NativeMemoryManager I will make that object accept the instance in its constructor and store it locally:

[source lang="csharp"]public SomeType( NativeMemoryManager mem ){ this.nativeMem = mem;}[/source]

Then it will use the reference its stores rather than calling NativeMemoryManager.Obtain() over and over...

So considering this particular case and others like it, do you see any problem with using the Singleton pattern? Or is there a better way to approach this?

C# stock quote API -- are you interested?

31 October 2012 - 11:40 PM

I've been screwing around for a good while on writing a C# API for retrieving live equity (stock) quotes. Tonight I got it working and I'm pretty impressed! This is pretty cool! Posted Image

As of right now the project is really an experimental rough-draft... no where near a real API I'm willing to put my name behind... But what I'm wanting to know is if people would be interested in this. Would you be interested in a very fast and easy-to-use C# API that can accept any stock ticker symbol and return a full, real-time quote, from which you can easily read the data and integrate it directly into your software?

If this might be of interest to you then vote up and/or reply to this post; if it seems like a good handful of people might be interested in this I will write a usable version of the aforementioned API and offer it as freeware -- free of any charges or royalties. Since I've already gotten all the details worked out and have a working mini-prototype the work will not take me too long! I just don't want to do all the work if no one wants it!

The API returns stock quote objects that look a bit like this::

[source lang="csharp"]public class StockQuote{ /*----------------------------------------------------------------------------- * FIELDS & PROPERTIES :: *-----------------------------------------------------------------------------*/ /// <summary> /// Ticker symbol of the stock /// </summary> public string Ticker { get; set; } /// <summary> /// Name of the company /// </summary> public string CompanyName { get; set; } /// <summary> /// Description of exchange on which stock is traded /// </summary> public Exchange Exchange { get; set; } /// <summary> /// Name of base currency in which prices are quoted /// </summary> public string Currency { get; set; } /// <summary> /// Last trade price /// </summary> public float Last { get; set; } /// <summary> /// Today's high price /// </summary> public float High { get; set; } /// <summary> /// Today's low price /// </summary> public float Low { get; set; } /// <summary> /// Today's total trade volume (in n-shares) /// </summary> public uint Volume { get; set; } /// <summary> /// Average daily volume /// </summary> public uint VolumeAvg { get; set; } /// <summary> /// Total market capitalization /// </summary> public double MarketCap { get; set; } /// <summary> /// Today's opening price /// </summary> public float Open { get; set; } /// <summary> /// Last session's closing price /// </summary> public float PrevClose { get; set; } /// <summary> /// Net change for the day (in points) /// </summary> public float NetChange { get; set; } /// <summary> /// Net change for the day as percent /// </summary> public float PercentChange { get; set; } /*-----------------------------------------------------------------------------* ******************************************************************************* *-----------------------------------------------------------------------------*/};[/source]

Sooo... let me know! Feel free to post any suggestions/ideas as well! ;-)

Regards,

--ATC--

Shouldn't be an issue?

29 October 2012 - 08:42 PM

I'm about to deploy a new DLL, and I'm wondering about something...

I have a structure in my library called "Rational", which essentially represents a fraction -- much like SlimDX.Rational... Mine, however, is a much more powerful mathematics structure that can do all sorts of things, such as calculating the GCD/LCD, reducing fractions, arithmetic with fractions, convert from fractions to decimals (and vice-versa) and more... However, in my structure I define conversion operators that can convert MY Rational type to/from SlimDX.Rational...

Problem is, I'm deploying this structure in a library that is intended as a generalized application development framework... users may or may not have SlimDX or be using it at all... for many users they will not be referencing SlimDX, and many may not even have it installed. It's my understanding that this should NOT be a problem and it would only cause my library to crash if someone tried to call a method that used a non-existent dependency... since these are operators and cannot be called directly that should never even happen!

So am I right? Is it ok to leave my conversion operators in there for the benefit of SlimDX users, or must it be removed?

Thanks,

--ATC--

P.S. -- I could really use some help with this question... hundreds of views, no answers... surely someone has deployed commercial libraries before and needed to register them?

Installation & registering assembly in GAC

28 October 2012 - 07:15 PM

Hey guys,

I have a C# library that's almost finished that's about to go into testing... I need to make an installer for it that will register the assembly with the GAC and install the DLL on the end-user's machine. I have both Visual Studio Pro 2008 and Express 2012 (Complete); since I wanted to use C# 5.0 and .NET 4.5 I did development in VS 2012 Express, but I guess I'll be using 2008 Pro to create my installer project and make my MSI file.

Can someone give me a run-down of what I need to do? Are there any restrictions on where the DLL should go? How to go about GAC registration through the installer? Any of info that could be helpful? Thanks!

Regards,

--ATC--

Different approach to "Camera" design?

26 October 2012 - 06:26 PM

I was just considering what the implications of a different approach to designing a camera base class might be...

[source lang="csharp"]// Traditional approach ::class CameraTraditional{ public Vector3 Up { get; set; } public Vector3 Target { get; set; } public Vector3 Position { get; set; }};// A different approach ::class CameraDifferent{ public Vector3 Position { get; set; } public Quaternion Orientation { get; set; }};[/source]

The pseudo-code example says it all... Normally, we implement a "camera" object with the properties "Up", "Target" and "Position" for creating a view matrix. But what if we toss that notion out and go with something more akin to any other 3D game entity, which has a "Position" and "Orientation" rather than calculating everything in terms of what direction is up and where the target is...?

What problems might this pose in game design? What advantages might it have? I was just curious about this idea so figured I'd ask...

Regards,

--ATC--

EDIT:

Also, what is the easiest way to decompose a projection matrix to retrieve the fov, aspect ratio and near/far clipping planes?

PARTNERS