Jump to content
  • Advertisement

Liam M

  • Content Count

  • Joined

  • Last visited

Community Reputation

223 Neutral

About Liam M

  • Rank
  1. Liam M

    List vs. Vector?

    In reality, this really doesn't have anything to do with C++ specifically, just about the behavior and differences between various data structures. The same conversation could be applied to C,C#, Java, etc. [/quote] Yes, correct, however in the rest of my post I was talking C++, and the comments I made regarding iterators were specific to C++ (although they may apply elsewhere). I should have added a disclaimer, well spotted.
  2. Liam M

    List vs. Vector?

    [font="arial, verdana, tahoma, sans-serif"] [/font] Yes, traversing a linked list is worst case O(n), however there is a lot that can be done to mitigate these problems. Sorting, for example, can increase real world performance in certain situations. Also consider that erasing from a vector may invalidate all and will certainlty invalidate iterators pointing to members subsequent to the one that was erased or inserted. Lists do not suffer from this behaviour. Your rule of thumb is generally correct, however one should not be naive about the implications of using either container (such as the behaviour of iterators), and often such rules are hard to apply in more complex, high performance systems. Personally, I favour lists, and will fall back on a vector where the benefits of random access or contiguous allocation are obvious. I like the graphic posted by karwosts, it's a good summary and shows a lot of the other containers which aren't as widely discussed. Who said C++ was easy?
  3. I second this, strongly. Also, 'NewWindow' is confusing, because 'new' could be read as a verb or an adjective, where as 'create' is a verb. I think it's important to name methods and functions such that they describe what they do unambiguosly. Self commenting code. Also, Win32 programming is an exercise in Hungarian Notation, and pulling teeth. Win32 also isn't C++: large portions of it are written in straight C. Thus, talking about Win32 style source code in the context of C++ is dangerous, it's comparing 20 year old apples to this seasons oranges.
  4. Liam M

    List vs. Vector?

    Long story short, a vector is contiguous in memory, and thus inserting, erasing and resizing are potentially expensive, as slow as O(n). A list is a linked list, more complicated and discontinuous, however insert and remove operate in constant time, or O(1), which is a lot faster (at least in notation, this may not be true is practice, big O is deceiving). There are many other differences with regard to iterators and specific functionality, but above is the primary differentiation between the two as concepts.
  5. Alright, another DLL question. So, I've been able to successfully obtain the 'interface' to my DLL, by using GetProcAddress and calling the resultant function. The structure it returns is defined as: #ifndef PLUGIN_KIT_C_SAFE_PLUGIN_HPP #define PLUGIN_KIT_C_SAFE_PLUGIN_HPP #include "C Safe\c_safe_documentation.hpp" #include "C Safe\c_safe_interface.hpp" #include "C Safe\c_safe_inventory.hpp" #include "C Safe\c_safe_version.hpp" #ifdef __cplusplus extern "C" { #endif struct CSafePlugin { // Get interfaces, free interfaces. // Type, arguments, version. Arguments in this order, types obvious. c_safe::CSafeInterface (__cdecl *get_interface_av)(const kt::byte*, const kt::byte*, c_safe::CSafeVersion); c_safe::CSafeInterface (__cdecl *get_interface_a)(const kt::byte*, const kt::byte*); c_safe::CSafeInterface (__cdecl *get_interface_v)(const kt::byte*, c_safe::CSafeVersion); c_safe::CSafeInterface (__cdecl *get_interface)(const kt::byte*); void (__cdecl *free_interface)(c_safe::CSafeInterface*); // Get the documentation for a plugin or interface. // Type is the only argument here, usage is simple. c_safe::CSafeDocumentation (__cdecl *documentation_t)(const kt::byte*); c_safe::CSafeDocumentation (__cdecl *documentation)(); // Type is the only argument here, usage is simple.; // Get the version of either a type or this plugin. c_safe::CSafeVersion (__cdecl *version_t)(const kt::byte*); c_safe::CSafeVersion (__cdecl *version)(); // Get the full documentation and versioning for this plugin. c_safe::CSafeInventory (__cdecl *inventory)(); // Get the name, brief description used for annotation. kt::byte* (__cdecl *description_t)(const kt::byte*); kt::byte* (__cdecl *name_t)(const kt::byte*); kt::byte* (__cdecl *description)(); kt::byte* (__cdecl *name)(); }; typedef CSafePlugin (__cdecl *plugin_entry_ptr)(); #ifdef __cplusplus } #endif #endif // PLUGIN_KIT_C_SAFE_PLUGIN_HPP This structure is used to return a few pieces of functionality back to the executable loading the DLL. The source code for the dll is: // Get the name, brief description used for annotation. extern "C" __declspec (dllexport) kt::byte* __cdecl description_t(const kt::byte*) { return ""; } extern "C" __declspec (dllexport) kt::byte* __cdecl name_t(const kt::byte*) { return ""; } extern "C" __declspec (dllexport) kt::byte* __cdecl description() { return "The Dummy Plugin."; } extern "C" __declspec (dllexport) kt::byte* __cdecl name() { return "Dummy Plugin"; } // The most important method of all... extern "C" __declspec (dllexport) CSafePlugin __cdecl entry_point() { CSafePlugin plugin = CSafeFactory::get_c_safe_plugin(); // Set a few things. // plugin.get_interface_av = 0; // plugin.get_interface_a = 0; // plugin.get_interface_v = 0; // plugin.get_interface = 0; // plugin.free_interface = 0; // plugin.documentation_t = 0; // plugin.documentation = 0; // plugin.version_t = 0; // plugin.version = 0; // plugin.inventory = 0; plugin.description_t = &description_t; plugin.name_t = &name_t; plugin.description = &description; plugin.name = &name; return plugin; } When I try and call the method 'plugin.name' using the returned struct inside the executable, I get an unhandled exception: access violation. Looking at the structure returned when I retrieve a CSafePlugin plugin interface, the values of the structure are as follows: get_interface_av 0x00000000 c_safe::CSafeInterface (const char *, const char *, CSafeVersion)* get_interface_a 0x00000000 c_safe::CSafeInterface (const char *, const char *)* get_interface_v 0x00000000 c_safe::CSafeInterface (const char *, CSafeVersion)* get_interface 0x00000000 c_safe::CSafeInterface (const char *)* free_interface 0x00000000 void (CSafeInterface *)* documentation_t 0x00000000 c_safe::CSafeDocumentation (const char *)* documentation 0x00000000 c_safe::CSafeDocumentation (void)* version_t 0x00000000 c_safe::CSafeVersion (const char *)* version 0x00000000 c_safe::CSafeVersion (void)* inventory 0x00000000 c_safe::CSafeInventory (void)* description_t 0x5b325130 char * (const char *)* name_t 0x5b325130 char * (const char *)* description 0x5b325140 char * (void)* name 0x5b325150 char * (void)* And having a look at the DLL export shows the following: description_t 0x10065130 0x00065130 2 (0x2) LMGM Plugin.dll G:\Working Copy\LMGM\Trunk\Plugins\LMGM Plugin.dll Exported Function name_t 0x10065130 0x00065130 5 (0x5) LMGM Plugin.dll G:\Working Copy\LMGM\Trunk\Plugins\LMGM Plugin.dll Exported Function description 0x10065140 0x00065140 1 (0x1) LMGM Plugin.dll G:\Working Copy\LMGM\Trunk\Plugins\LMGM Plugin.dll Exported Function name 0x10065150 0x00065150 4 (0x4) LMGM Plugin.dll G:\Working Copy\LMGM\Trunk\Plugins\LMGM Plugin.dll Exported Function entry_point 0x10065160 0x00065160 3 (0x3) LMGM Plugin.dll G:\Working Copy\LMGM\Trunk\Plugins\LMGM Plugin.dll Exported Function Any ideas as to why I'm getting an unhadled exception when I call name()? Any assistance would be appreciated.
  6. Aaah, wait a second, well spotted Erik! I was missing a pair of... #ifdef __cplusplus extern "C" { #endif Around the header file where I was declaring the method. Now I'm getting a much nicer export name, and a non zero return from GetProcAddress. Thank you sir!
  7. Thanks Erik, appreciate the suggestions. I have scanned the DLL using DLL Export Viewer (if you could suggest an alternative application you are familiar with, it would be much appreciated), and it shows the 'Function Name' to be: CSafePlugin __cdecl entry_point(void) I assume this is the function name should match that with which I am to load the function using. I've tried various permutations of this name, to no avail. I've also anticipated the C++ name mangling, and have declared the methods as per Microsoft documentation (http://msdn.microsof...34d(VS.80).aspx): Microsoft suggests: [font="Consolas, Courier, monospace"]__declspec(dllexport) void __cdecl Function1(void);[/font] [font="Consolas, Courier, monospace"][font="arial, verdana, tahoma, sans-serif"]I'm using:[/font][/font] [font="Consolas, Courier, monospace"][font="arial, verdana, tahoma, sans-serif"] [/font][/font][font="Consolas, Courier, monospace"]_declspec (dllexport) CSafePlugin _cdecl entry_point();[/font] [font="Arial"] [/font] [font="Arial"]So this is where I am, a bit puzzled.[/font]
  8. I'm rewriting a plugin library I wrote a few years ago, just updating it to fit it into the company codebase. Here's the fragment that's causing me trouble: // Loading and unloading plugin files. void Plugin::load(kt::EncodedString filename) { #ifdef KT_MICROSOFT_VISUAL_CPP // Try and load the DLL. DLLHandle = LoadLibrary(filename.to_wide_string().c_str()); if(!DLLHandle) { DWORD lastError = GetLastError(); // TODO: throw an exception. } plugin::plugin_entry_ptr entryPoint = 0; entryPoint = (plugin::plugin_entry_ptr)GetProcAddress(DLLHandle, "entry_point"); Internal = entryPoint(); IsLoaded = true; #else // TODO: Support other platforms. #error Unsupported Compiler #endif } And that typedef: typedef CSafePlugin (__cdecl *plugin_entry_ptr)(); Now, I'm trying to use GetProcAddress to get at the exported function "entry_point". Using DLL Export Viewer, I've observerved the function is being exported: CSafePlugin __cdecl entry_point(void) 0x10065130 0x00065130 1 (0x1) Dummy.dll G:\Working Copy\Dummy.dll Exported Function LoadLibrary(...) appaears to work, and returns a non zero result. However, the call to GetProcAddress fails (returns 0) can anyone offer a suggestion as to what I'm doing wrong here? I can provide necessary code, any assistance is much appreciated.
  9. MultiByteToWideChar. EDIT: and actually OS X "prefers" UTF16 (Cocoa and CoreFoundation) and UTF8 (POSIX) at different layers of the OS. UTF32 is rather rare, AFAIK. I'm not a big Linux user, but I suspect that's quite UTF8-heavy too. EDIT2: I can see lots of functionality in ICU::UnicodeString that allows conversion to/from UTF8 and to get the raw data e.g toUTF8() and getBuffer(). [/quote] Aaah, well spotted, I didn't notice getBuffer. I know about the facility for UTF-8 and UTF-32 (and am using both extensively), it was just UTF-16 I couldn't find. Thanks for the heads up. And I should clarify, when I saw 'prefers' I'm referring the width of wchar_t, I got a little confused there, talking about the operating system and the compilers commonly used on these 3 platforms.
  10. Games of this vintage were written in C, with some assembly thrown in where performance was required. Assembly isn't that bad once you're comfortable with it, and when you don't have a lot of headroom as far as memory and raw speed are concerned, C and assembly can be pretty formidable.
  11. Hi Guys, I use UTF throughout my libraries, however am building a small kit to handle DLL's in windows. I'm trying to use the function LoadLibrary to interact with a DLL, however the filename must be formatted as an LPCWSTR (long pointer to a C wide string). Is there a reasonable way to convert UTF-8 to a LPCWSTR? I'm using the ICU library for UTF, which uses UTF-16 internally, with conversions to UTF-8 and UTF-32 available. I can't find a method to access the UTF-16 data inside the ICU::UnicodeString, which may solve my problem (I'm of the impression windows prefers UTF-16, if it's going to have to deal with UTF. Linux and OSX prefer UTF-32). If anybody has experience with ICU, I'd appreciate feedback on getting to the UTF-16 data. The documentation for the ICU:: Unicode string is here: http://icu-project.o...codeString.html I've looked over it many times, however this simple piece of functionality continues to escape me. Regards, Liam
  12. lt's been a very long time (3, 4 years?) since I've played with real-time rendering, What I've hacked together is a frame buffer, associated with a texture, on which I want to render a scene and then convert to a Qt QImage to save it to a file. The scene is an orthographic scene which is encompassed by bounds. the code snippet, is as follows: BoundingBox bounds = bound_scene(10); unsigned int frameBuffer; unsigned int depthBuffer; unsigned int fBOTexture; glGenRenderbuffersEXT(1, &depthBuffer); glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, bounds.extent(0), bounds.extent(1)); glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depthBuffer); glGenTextures(1, &fBOTexture); glBindTexture(GL_TEXTURE_2D, fBOTexture); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bounds.extent(0), bounds.extent(1), 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glBindTexture(GL_TEXTURE_2D, 0); glGenFramebuffersEXT(1, &frameBuffer); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, frameBuffer); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, fBOTexture, 0); glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depthBuffer); GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER_EXT); if(status != GL_FRAMEBUFFER_COMPLETE_EXT) { throw "Unable to create frame-buffer: graph capture failed."; } glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, frameBuffer); glPushAttrib(GL_VIEWPORT_BIT | GL_ENABLE_BIT); glViewport(bounds.minimum(0), bounds.minimum(1), bounds.extent(0), bounds.extent(1)); glClearColor(1.0f, 1.0f, 1.0f, 1.0f); glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); glLoadIdentity(); // Render to the buffer. render(); // Read out of the buffer. int bytesPerLine = bounds.extent(0) * sizeof(GLubyte) * 3; int bufferSize = bytesPerLine * bounds.extent(1); GLubyte* data = new GLubyte[bufferSize]; glReadPixels(0, 0, bounds.extent(0), bounds.extent(1), GL_RGB, GL_UNSIGNED_BYTE, data); glPopAttrib(); glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); QImage image((uchar*)data, bounds.extent(0), bounds.extent(1), bytesPerLine, QImage::Format_RGB888); image.save("C:/test.bmp"); delete[] data; No doubt many errors, i wrote that late at night. Specifically, the problems I'm having are as follows: Resulting image has artifactsResulting image doesn't appear to encompass the scene area. So, how can I improve the above, and ideally, get it working?
  13. Liam M

    Qt 4.7 Help with QTreeView

    Quote:Original post by toogreat4u I have found another forum that responded fast to my Qt specific questions. I know this site isn't geared toward Qt GUI programming so I decided to search other avenues. If anyone is working with Qt and would like to know how I solved it I will be glad to share it with you. Thanks everyone! (not being sarcastic as this site has been an awesome resource!) I'd be interested to know, I've tried a few forums, but all the Qt ones are terrible. Even the new one Nokia has set up is bad: it reeks of web 2.0, and is a huge pain in the butt to navigate.
  14. Quote:Original post by iceisfun Well you might try http://www.memtest86.com/ just to be safe. Well, I'm running x68, plus my memory is fine, it's just Visual Studio which bites the dust from time to time. Never had a BSOD or hardware death, my machine gets tested once a month and is used exclusively for development. I suspect it may be WPF related, that sounds like a good avenue to go down. Any ideas on that front would be appreciated!
  15. I found this article, seems to be a useful hint, not sure if it's what I'm after though: Click
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!