OOP for CUDA and OpenCL integration [closed] - c++

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Here's the problem: I'm developing a framework (CLCuda, not the most creative name out there) where the programmer instantiates one object, and depending on what the system supports (CUDA or AMD OpenCL), will use the corresponding methods, without having to change any line of code to that.
I have a abstract class named CLCuda (pure virtual methods, but could be just virtual), and the two classes that implement its methods are CLCudaCUDA and CLCudaOPENCL.
I wanted to have something like this: instantiate one object that will iniciatlizate CUDA or OpenCL, depending on what graphics card the user have, that can access the methods of the available platform (through the class CLCudaCUDA or CLCudaOPENCL).
I already coded the methods of CLCudaOpenCL and CLCudaCUDA (hard times doing that), so my problem is with OOP.
How could I structure my classes?
If anyone can help... thanks very much!

Your problem seems to suggest a "Factory" design pattern. Presumably you have a method to determine which is supported on the current host, so you should leverage that in the implementation of your factory.

Related

Architecture of c++ projects [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I am from JAVA so please please guide me if i am wrong.
In Java we mostly use a singleton class and create all the class objects thought the singleton class.
What about in c++?
I know we can use singleton but mostly while going through most of the stack overflow questions. Most of them says it's not good to use singleton in c++
Can you recommend some book or some project which will be easy to understand?
Whether you're writing in C++ or Java singletons have many, bad implications.
They make it very difficult to test as their static nature preculdes late binding to, say, sway a real database with a stub that's quicker and has fewer depencies.
They also provide a fig leaf for global variables, trying to make them masquerade as a good design decision. Take a look at the alternatives, it'll pay off in a better design. You may want to look into dependency injection for ways to design a more testable system without singletons.

What is "Register a class" in C++ [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
What does it mean "register a class", if we are talking about C++ and OOP, not about register, COM or some other libraries?
In the context of pure C++, without respect to any specific platoform or library, "register a class" has no meaning. This is not a language concept, nor is it any design pattern I am aware of.
It does however have at least two meanings the Windows world. For posterity and future readers:
You can register a Window class. A Window class contains some basic functionality and other parameters that effect how specific windows behave on-screen.
You can register a COM class so that specific instances of that COM class can be instantiated by clients.
"context was in articles about OOD, and it was said something like it is good practice to plan your classes in the way that for changing some aspect of program it will be enough to write new class, register it and you get new staff"
Now it seems to me you are talking about the publisher/subscriber pattern. It allows loose coupling between caller and callee.
You can find a C++ implementation everywhere, in the GoF book, or here:
http://rtmatheson.com/2010/03/working-on-the-subject-observer-pattern/

Strategy Pattern at runtime? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have a strategy pattern, and would like to run it in a main loop in a game for example. The problem is there will be a memory leak If I'm not deleting the instance, and I also would like to use that instance somewhere else. How can I deal with memory allocation/deallocation in a strategy pattern.
CompressionContext *ctx = new CompressionContext();
//we could assume context is already set by preferences
ctx->setCompressionStrategy(new ZipCompressionStrategy());
//get a list of files
ctx->createArchive(fileList);
Use an std::shared_ptr<CompressionContextBase> instead of a CompressionContextBase* (i.e. a raw pointer).
Edit: This is just a suggestion, based on the information you provided, there may be other smart pointer implementations with different semantics, such as e.g. unique_ptr, which might be more suited. As #akappa suggests, you may want to read up on the topic more, to make a better decision -- again, based on the information in the question, you probably want a shared_ptr but there might be additional considerations you omitted.

How to encrypt a text [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I need to implement a simple text encryption in C++ without using any existing framworks. This is purely for educational purpose to learn the in-and-outs and to learn the way to implement such a system. I am not planning to implement this in production code. I can use Windows APIs but it won't be cross platform. I am trying to learn something can work across multiple platforms. the best way to implement this is implement using C/C++. Please share good resources or links in this regard.
Depending on what you actually want, you could look at the CipherSaber project: instructions to implement your own RC4 encryption code for a simple IV+text format.
However this is an academic exercise only: you should never use your own crypto code in production unless you really know what you're doing. You could also read Schneier's Applied Cryptography for a good introduction to all of this stuff.

C++ windows registry editing [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
hey i need c++ program to edit windows registry
One good program is Regedit.exe. It is probably written in C++.
Qt has an excellent framework for editing registy - that is, QSettings. And for bonus points, if you happen to change your mind and go Linux, your code would still work, storing your data in .ini-style configuration files.
Take note that Qt is very fat for a C++ library, but also very functional. There's a crazy lot you can do with it. I also absolutely recommend it for GUI.
There are probably a thousand small C++ wrappers for registry access. Of course I wrote my own, too. See the class RegistryKey in my envvc program. It's only read-only access, but you'll get the idea.