Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

100 Neutral

About Thetan

  • Rank
  1. Quote:Original post by rip-off If you have a function that takes a const std::string reference then you can pass a C string to it: I guess it's worth mentioning that the argument being const or referenced are not required. Passing a C string to an argument that is expecting a std::string works by passing the C string to the std::string constructor that accepts a single C string (the proper term as i think its called is implicit type conversion). Also, if your passing a C string to an argument thats expecting a reference to a std::string, your compiler usually will first create a temporary unnamed std::string object from the given C string, then pass its reference as the argument. This would be ever so slightly less efficient then passing a C string as an argument thats expecting a std::string, due to the non-creation of a temporary object, and the avoidance of passing a seemingly redundant reference.
  2. Quote:Original post by JohnBolton RVO: Foo Bar() { ... return Foo( x, y, z ); } NRVO: Foo Bar() { Foo f( x, y, z ); ... return f; } So basically, if i absolutely need to create an object and populate via the algorithm of the function, there is no way to even hint the RVO?
  3. Different sources have told me different ways to hint to the compiler to use the RVO. I know there isnt a garuntee a compiler will implement the optimization no matter how you hint, but whats the best way?
  4. To answer your question, it would definitely be much faster to apply quicksort afterwards. Applying quicksort every time an element is added just gives you so many unneeded comparisons. To give you some good advice though, have you considered using the C++ std::set container? A set is a sorted associative container (this basically means that elements are automatically sorted upon insertion into the set), it is associative in such a way that the key is the element and naturally the element is the key. No two elements can share the same key in a set, thus meaning that all elements within a set are unique.
  5. string based delimiter systems just wont do. Say for example who's to say what could happen in the original implementation that the user agent contains the substring "==>" somewhere in it (remember user-agent is easily modifiable). The simplest method i can think of would be to simply build a key based array of the client data (you can do this in one line if you want to). Then you can serialize() the array, send the serialization off to the DB(3 lines so far, the array, the call to serialize, then the db query. Hell if you arent going for verbose code it could be a single line.). Then when you pull that field out of the DB you can pass it through unserialize() and the array will be automatically rebuilt.
  6. Its important to remember that AJAX is more of a philosophy then an actual specific technology. Thus there are numerous combinations of technologies that could be used in an AJAX application. However, you at least need a server side scripting engine, a client side scripting engine, and a transmission protocol so they can talk to each other. Some server side scripting engines include: + PHP + ASP + Perl + Python + etc Some client side scripting engines include: + javascript + Java + Flash ActionScript (actually pretty fun to work with) + etc Some transmission protocols + XML + JSON (i prefer this anyday over XML in an AJAX environment, its basically serialization) + etc An interesting technology you might want to take a look at is known as Ruby on Rails (RoR). You can think of RoR as a web extension for the Ruby programming languages thats meant to develop rich AJAX pages in a pure Ruby environment. Its kind of nice just having to work with a single language as oppose to working with separate client and server scripting languages and a transmission protocol. RoR basically does all the AJAX work for you.
  7. I guess its worth mentioning that while the following is erroneous code. char* pStr = "Some string"; *pStr = 'a'; This next example is perfectly valid and will not cause a segfault. char pStr[] = "Some string"; *pStr = 'a'; This is because the char* type for a string literal is stored in read only memory, while the second example localizes the string literal on the stack for each frame it is called in.
  8. Like some one mentioned before me, the simplest solution would be to not use regex for the ? matching section. The following is something i whooped up real fast, and works in all my test cases <?php ////// different test queries i used. //$query = "SELECT * FROM table WHERE field1='where\'s john?' AND field2=?"; //$query = "SELECT * FROM table WHERE field1=? AND field2='where\'s john?'"; $query = "INSERT INTO table (field1, field2) VALUES ('ra\'wr?', ?)"; $flag = FALSE; // used to determine if were in single quotes $peices = explode("'", $query); foreach($peices as $key => $peice) { if ($flag) { if (substr($peice, -1) != "\\") $flag = FALSE; continue; } // Definetely outside of single quotes here // apply replacements here via preg_replace() // or some other replacement method. $peices[$key] = str_replace("?", "'[Thetan]'", $peice); // just for shits and giggles $flag = TRUE; } $query = implode("'", $peices); // make query the glue'd together pieces of $peices echo "{$query}\n"; // just testing results ;) ?> of course you can wrap it in a clean little easy to use function. [Edited by - Thetan on April 22, 2007 12:46:26 PM]
  9. I've just read the tutorials "Haskell for C programmers" and "The gentle introduction to Haskell". Can anyone please recommend me some books and other good articles.
  10. I'm trying to increment a bitset by one. I know this is wrong, and g++ bitches when i try it. workLoad.bitset(workLoad.to_ulong()+1); but how would i do this?
  11. Quote:Original post by JohnBolton If you use just the base container instead, then you must create your own version of a stack or queue. Why would anyone waste time creating their own version when one already exists? Maybe I'm missing something, but why would you have to create your own version? Everything you would be able to do with a std::stack<int, std::vector<int>> you can do right out of the box with a simple std::vector<int>. Performance never was a concern for me, because I'm aware of the STL's awesome inlining. I just want to know if there are more benefits to using container adapters other then typing .push() instead of .push_back() etc. Thanks Antheus
  12. Why would anyone use a container adapter such as stack or queue instead of just using the base container alone? Is the only gain a simplified interface? Thanks in advance
  13. Thetan

    modulation sensation

    Quote:Original post by TheAdmiral You don't know the function prototypes at compile-time, so there will be trouble implementing the plugins in advance. One idea would be to create your own 'variant' data type, which encapsulates any other data type you need to communicate. This way, you could write all the plugin functions so that they pass (and possibly return) a pointer to an array/vector of variants. This way, your parameters are flexible in type and quantity, but the prototype is always the same. This does, however, put extra work on the plugin author. actually my way around that was to set 2 standardized parameters for each module. 1.) An "IRC Handle" 2.) A parsed IRC Header ontop of that the botcore knows the name of the function to load due to the fact that the name of the function should always be hook(module-filename-without-extension-here) Quote:Original post by TheAdmiral Ultimately, the core application will not be able to use the plugins unless it knows something about what they do, so perhaps if you give us more details on how the plugins interact with the core then we can provide a more suitable solution. ok, i got that far on my own, but my speedbump isnt how do i get the botcore to use the module. My speed bump is how do i get the module to utilize the botcore (or atleast the botcore functions)
  14. Thetan

    modulation sensation

    right i know all the steps for dynamic linking, but my problem is a design issue or so i think. let me try to illustrate the problem. bot core: module: ------------- ------------------ |IRCAction()| |hookAct(){ | |IRCMsg() | <---> | IRCAction();| |IRCJoin() | |} | |... | ------------------ ------------- How do i get the compiler to realize that i want the module to call a function from the botcore?
  15. ok, im working on an irc bot system that runs almost entirely off of customizable modules. I want it to be set up so that whenever you want to add another module or change a previous one you dont have to recompile the whole bot. My intent is to build something that works similar to the way firefox extensions work. So instinctively i turn to dynamic linking, but i remembered that i have 0 experience in working with dynamic linking. My problem is that all of the external functions i try to call from my modules are undefined (this makes perfect sense to me, but i dont get how to make it work like i want it to). here, code talks best a simple module: #include "../khook.h" void hookAct(struct ircHandle *ih, struct ircHeader *ph) { if(ph->message[0] == '+' && strncmp(&(ph->message[1]), "act", 3) == 0) IRCAction(ih, ph->channel, &(ph->message[5])); // the function that exists in the program loading this module } khook.h (my pathetic attempt to solve the problem) struct ircHandle { int port, sock; char nick[50]; }; struct ircHeader { char *raw; char *nick; char *name; char *vhost; char *channel; char *type; char *target; char *message; }; // me attempting to extern the outside functions void IRCUser(struct ircHandle*, char*); void IRCNick(struct ircHandle*, char*); int IRCOpen(struct ircHandle*, char*, int, char*); char IRCGetChar(struct ircHandle*); char* IRCGetHeader(struct ircHandle*); struct ircHeader* IRCGetParsedHeader(struct ircHandle*); void IRCHeaderFree(struct ircHeader*); int IRCPing(struct ircHandle*, struct ircHeader*); void IRCNotice(struct ircHandle*, char*, char*); void IRCKick(struct ircHandle*, char*, char*, char*); void IRCPrivmsg(struct ircHandle*, char*, char*); void IRCAction(struct ircHandle*, char*, char*); void IRCJoin(struct ircHandle*, char*); void IRCQuit(struct ircHandle*, char*); The failure: [r3d@localhost PRIVMSG]$ gcc -fPIC Act.c /usr/lib/gcc-lib/i386-redhat-linux/3.3.3/../../../crt1.o(.text+0x18): In function `_start': : undefined reference to `main' /tmp/ccsuf1o1.o(.text+0x55): In function `hookAct': : undefined reference to `IRCAction' collect2: ld returned 1 exit status [r3d@localhost PRIVMSG]$ ideas, sugestions, and bitch slaps of obvious truth are all welcome <3 Thetan
  • Advertisement

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!