Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 29 Sep 2011
Online Last Active Today, 05:13 AM

#5223502 Why high level languages are slow

Posted by lwm on 15 April 2015 - 01:23 PM

This discussion is soooo old smile.png


The project I work on at my day job is *very* large scale. Some parts of it have hard real-time requirements and are basically written in C with classes. Some parts are C++ because they are compute-bound. But the majority of the components is written in C#, because performance simply isn't the top priority, productivity is.


Use the right tool for the job and be done with it.


Most developers I meet every day are entrenched in "their" world, but I love switching between the worlds and the languages. Spend the morning writing "fast" code, go to lunch and then switch over to writing "nice" code. What really annoys me though, is the fact that everyone and their dog calls themselves a "C# developer" nowadays after reading a few tutorials. It's sad to see so many programmers being completely oblivious of all the nice aspects of the "high level" languages that we willingly paid for by sacrificing performance.

#5218347 String: How to find the most common character occurrence.

Posted by lwm on 22 March 2015 - 04:56 PM

Unless there are predetermined performance constraints, I would always go for a simple solution first:

private static string GetAnyMostFrequentCharacter(string input)
        throw new ArgumentOutOfRangeException("input");
    var group = input.GroupBy(c => c).OrderByDescending(g => g.Count()).First();
    return string.Format("<{0}, {1}>", group.Key, group.Count());

Or to get all most frequent characters:

private static string GetAllMostFrequentCharacters(string input)
    if (!input.Any())
        throw new ArgumentOutOfRangeException("input");
    var groups = input.GroupBy(c => c).OrderByDescending(g => g.Count());
    var firstLargestGroup = groups.First();
    var allLargestGroups = groups.Where(g => g.Count() == firstLargestGroup.Count());
    var stringBuilder = new StringBuilder();
    foreach (var group in allLargestGroups)
        stringBuilder.AppendLine(string.Format("<{0}, {1}>", group.Key, group.Count()));
    return stringBuilder.ToString();

#5201877 Server socket with select, thread pool and queue based approach

Posted by lwm on 05 January 2015 - 02:08 AM

Now lets say as you said, fd1 is currently in process and meanwhile we get the data from fd1 again. Again that fd1 will be added in deque in main function and any thread whichever is free can consume that. If all threads are busy in processing, we will be keeping that fd1 in deque.  

What exactly is "fd" referring to? Did I accidentally skip over an explanation somewhere?

rip-off already mentioned that a single receive-call does not necessarily correspond with one single logical request. You may need multiple receive-calls until you have a full request. Or you may receive multiple requests (the first and last ones possibly being incomplete) with one receive call.


You mentioned 100 concurrent clients. Is that a realistic goal?

If so, using blocking IO calls is probably not a good idea. Use asynchronous IO wherever possible.

I just finished implementing a diagnostics server with soft real-time requirements at work and was pleasantly surprised how elegant the whole thing became once I left all the nasty waiting and blocking to the software that does it best: the operating system.

Is boost::asio an option for you?

#5186887 Example code wanted for Broad Phase Collision Detection.

Posted by lwm on 14 October 2014 - 05:28 AM

There are many ways of implementing a broad phase and there is no single correct way. It depends on many factors like whether you're in 2D or 3D, the number of entities, the average distance between entities, whether most of them are static or dynamic, etc. You could try:


  • Brute Force: This can actually be a good choice for a reasonable number of entities if you can make your data structures cache-friendly.
  • Spatial Partitioning: There are many examples on Quadtrees and Octrees out there.
  • Spatial Hashing: Good for many moving entities since reinsertion is fast, but has other drawbacks instead.

I've been using BepuPhysics for some time now. You can look at the source code at CodePlex.

#5175210 Destructor in vector called too often

Posted by lwm on 21 August 2014 - 03:21 AM

Would still be nice though if anybody with visual studio 2013 or the 2012 November compiler CTP could also test the code and confirm that this is happening for him too.


I'm sorry to say that I can't reproduce the problem with Visual Studio 2013 Update 2.

#5174628 How can I display Unicode characters like "ä" or "语" in my game?

Posted by lwm on 19 August 2014 - 12:40 AM

DirectWrite uses a 2D render target. I don't know if and how I can use this for a 3D game with a 3D render target...


Combining DirectWrite/Direct2D with D3D11 is definitely possible. I used them both for a project a while ago (it used SharpDX, but that doesn't really make a difference). Unfortunately, I don't have access to that project right now.


SpriteFont uses Windows 8.1 SDK and DirectX 11.1 math. Will it work with Windows Vista, Windows 7 and Windows 8(.1) and on graphic cards that only support DirectX 11?

DirectXTK should be usable on all platforms that support DX11 (you can still use a lower feature level). According to the Codeplex page, Vista SP2 and higher are supported.


And is there a way to get the size of the text before it is rendered? I need to know the width of each word (or letter) to implement scrolling, so how can I do this with DirectWrite or SpriteFont?

SpriteFont provides a MeasureString method that returns the size of a given string in pixels.

DirectWrite allows you to do get all kinds of information on the text to be rendered and implements many formatting options.

#5174440 How Would You Make A Quad Based On a Direction in 3D.

Posted by lwm on 18 August 2014 - 07:26 AM

Some pseudocode: 

dir = normalize(target - start)
up = (0, 1, 0)
halfSize = size / 2

// todo: handle case when (dir == up)
o1 = cross(dir, up) * halfSize
o2 = cross(o1, dir) * halfSize

p1 = start + o1 + o2
p2 = start + o1 - o2
p3 = start - o1 - o2
p4 = start - o1 + o2

#5174436 How can I display Unicode characters like "ä" or "语" in my game?

Posted by lwm on 18 August 2014 - 07:09 AM

What about DirectWrite?

#5173833 [SharpDX] Unable to render texured models using BasicEffect

Posted by lwm on 15 August 2014 - 03:06 AM

When you inspect the loaded model in the debugger, what do the InputElements in the VertexInputLayouts look like? Do they include a "TEXCOORD" element? If they don't, are you sure that your model contains texture coordinates?

The SharpDX Toolkit automatically chooses an appropriate Vertex struct and corresponding VertexInputLayout for you. If there is no InputElement for texture coordinates, the model compiler probably wasn't able to find any texture coordinates in the source model.

#5173812 [SharpDX] Unable to render texured models using BasicEffect

Posted by lwm on 15 August 2014 - 01:33 AM

When you set TextureEnabled to true, BasicEffect will switch to a version of the shader that expects your vertices' texture coordinates to be in element "TEXCOORD0". However, according to the error message, your vertices don't provide any coordinates with that name. How are you loading the model and what vertex type are you using? If you're using a custom one, maybe you forgot to add the attribute to the struct's field that holds the texture coordinates?

#5173513 Alternative to FBX for Animation Export ?

Posted by lwm on 14 August 2014 - 12:59 AM

I agree with Promit. Reading Collada files (.dae) with Assimp works well for me.

#5173350 Using SharpDX.Toolkit.Effect classes as shader replacement

Posted by lwm on 13 August 2014 - 08:59 AM

Thanks for real help to all *sarcasm*


What did you expect? Few people are going to sit down and write multiple samples just for you without even knowing what parts of the API you're struggling with.


The toolkit folder in the samples repository for SharpDX contains multiple samples that use custom effects. For example: CustomEffect, SpriteBatchCustomEffect and StreamOutParticles. What part of the API do you need more info on?

#5133537 SharpDX - SwapChain1 - where are the constructors?

Posted by lwm on 22 February 2014 - 07:35 AM

Well I have my answer. The folks at SharpDX actually haven't updated the main download for a while. I need the DirectX11_2 build of SharpDX, which I kind of have to do myself, it seems.


Make sure to use the "Latest Dev Package" download link on the SharpDX homepage. It includes the binaries for 11_2.

Edit: Xoofx was faster smile.png

#5131554 Texturing an object (DX vs Shader)

Posted by lwm on 15 February 2014 - 09:13 AM

So you are saying switching textures will be a bottleneck regardless?


There is no way for us to know if it will be a bottleneck in your case. Every state change has a certain cost. How big that cost is (and how relevant that cost is for a given system) depends on lots of different factors, but for DX9 you probably want to sort by shader first, then by texture, then by everything else.

#5131483 Texturing an object (DX vs Shader)

Posted by lwm on 14 February 2014 - 11:59 PM

Yes. You still want to switch between textures, shaders, and all other bound resources as little as possible. With DX9, switching between shaders is particularly expensive.