Skip to main content
gamedev.net
🔒 Locked

Discuss content management code draft

Started by Semei Feb 25, 2011 at 12:16 PM 5 replies 1.4k views
Original Post
Semei
Semei
Hi! Im creating content management system for DX11 game and im looking for implementation that is simple, yet will not give a lot of headache later.

Currently im thinking about guiding content creation/destruction through one class and managing resource release in content class, and not bothering to do so in object level.

Code here is C#, syntax is irrelevant - but please suggest any corrections related to implementation if you are able to

Any suggestions, warnings and corrections welcome!

CODE
bubu LV
bubu LV
You are leaking a lot of resources. SharpDX doesn't dispose them automatically. You must manually call Dispose (or Release) method on them. For example around line 94: ShaderBytecode, ShaderSignature.

Also this: foreach (dynamic obj in dictionary.Values) in line 178 is very bad for performance. You should simply do this:
public void ReleaseFromDictionary<T>(Dictionary<string, T> dictionary, AppTiming currentTiming) where T: ComObject
{
foreach (var kv in dictionary)
{
if (NeedRelease(kv.Value.releaseTiming, currentTiming))
kv.Value.Release();
}
}
Semei
Semei
Hmm, i dont think im leaking anything, its being disposed in extended class that contains bytecodes etc:


/// <summary>
/// [Ex]tended class of pixel shader, containing compiled pixel shader,
/// associated bytecode, used reference count and name of file shader was loaded from
/// </summary>
public class PixelShaderEx : BaseContentObject
{
#region variables
/// <summary>
/// Actual vertex shader
/// </summary>
public PixelShader shader;
/// <summary>
/// Associated shader bytecode
/// </summary>
public ShaderBytecode bytecode;

#endregion

public PixelShaderEx(string name, PixelShader shader, ShaderBytecode bytecode, AppTiming releaseTiming)
{
this.name = name;
this.shader = shader;
this.bytecode = bytecode;
this.releaseTiming = releaseTiming;
}

public override void Release()
{
shader.Release(); //this
bytecode.Release(); //and this!
}
}


Why do you think that using dynamic is poor performance? O_o;;
Also class contained in T is created from base of BaseContentObject not ComObject. So it would be


public void ReleaseFromDictionary<T>(Dictionary<string, T> dictionary, AppTiming currentTiming) where T: BaseContentObject
{
foreach (var kv in dictionary)
{
if (NeedRelease(kv.Value.releaseTiming, currentTiming))
kv.Value.Release();
}
}
bubu LV
bubu LV
Ok, I did not take a look at PixelShaderEx class. Btw you can dispose bytecode after shader compilation, no need to keep it together with shader.

Because dynamic object is runtime feature. It doesn't know what members or methods its object have. That is resolved at runtime. Static types knows this information at compile time, so they resolve this information during compilation.
Semei
Semei
Its not as fast, but not "slow", at least not as reflection.. But you are right, i dont need to use dynamic in this case as declaring specific type of T is more efficient.
bubu LV
bubu LV
Found some microbenchmark that displays 10x increase in time needed to call dynamic method: http://www.buunguyen.net/blog/fasterflect-vs-c-4-0-dynamic.html
Semei
Semei

Found some microbenchmark that displays 10x increase in time needed to call dynamic method: http://www.buunguyen...-0-dynamic.html


That's not relevant. If im disposing objects, then a second more or less would maybe make a difference, but not few ms, im not disposing millions or resources every frame, but just few thousand on end of level.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.