Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
T

Tyler Elric

@Tyler Elric
About
Posts
6
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Reading hexadecimal numbers out loud
    T Tyler Elric

    Same here, except I say "OH-EX" and then the numbers/letters. :D :-D :laugh:

    The Lounge help question learning

  • vString
    T Tyler Elric

    I use g++/gcc ( MinGW ) -- not Visual Studio -- http://msdn.microsoft.com/en-us/library/dd293665.aspx[^] Is this what your'e referring to as "Move semantics" ?

    C / C++ / MFC javascript html com graphics debugging

  • vString
    T Tyler Elric

    Well, I would BUT there are some problems I've found with std::vector<>: 1) Deep copies -- Every time I resize the vector, a constructor is called, or an operator = () is called. I can't remember which. Either way, if an object in an std::vector<> requires deep copies to be made, lots of time is just wasted allocating, releasing, and assigning memory. 2) For instance, take my vString class. If I had used std::vector for it's base type, things might be a little more complicated, and time consuming. ( With #1 in mind )

    The roof's on fire, but it keeps out the rain. So clench your fists, and enjoy the pain.

    C / C++ / MFC javascript html com graphics debugging

  • vString
    T Tyler Elric

    Oh, okay. My apologies!

    class Range{
    private:
    int mStart,mSize,myID;
    public:
    Range(int aStart,int aSize):mStart(aStart),mSize(aSize){}
    Range(Range& r):mStart(r.mStart),mSize(r.mSize){}
    Range(const Range& r):mStart(r.mStart),mSize(r.mSize){} //needed to return 'by value'
    bool operator () (int x){
    return x>=0? (x

    Inside Vector<> Class:

                Range All( int size = -1 ) {
                        if(size==-1) size = arraySize;
                        const Range ret(0,size);
                        return ret;
                }
    

    And the problematic code:

                T& Add(const T& nElement, int indice = -1){
                        Allocate();
                        ++arraySize;
                        Range ran = All();
                        indice = ran\[indice\];
                        if ( indice < 0 ) indice = arraySize + indice;
                        if(sizeof(T)<=sizeof(T\*)){
                                if(static\_cast(indice+1)!=arraySize) memcpy(&(((T\*)tElements)\[indice+1\]),&(((T\*)tElements)\[indice\]),sizeof(T)\*(arraySize-indice-1));
                                memcpy(&(((T\*)tElements)\[indice\]),&nElement,sizeof(T));
                                return (((T\*)tElements)\[indice\]);
                        } else {
                                memcpy( &(tElements\[indice+1\]),&(tElements\[indice\]),sizeof(T\*)\*(arraySize-indice));
                                if(construct) return \*(tElements\[indice\] = new T(nElement));
                                else{
                                        T\* nPtr = (T\*)new char\[sizeof(T)\];
                                        memcpy(nPtr,&nElement,sizeof(T));
                                        return \*(tElements\[indice\] = nPtr);
                                }
                        }
    
    C / C++ / MFC javascript html com graphics debugging

  • vString
    T Tyler Elric

    ** Also, when you see something like

    if(sizeof(T)<=sizeof(T*)){

    } else {

    }

    I'm aware that a T* is almost always going to be 4 bytes long, but I felt the need to place things this way. I'm also aware that most of my code is lacking heavily in comments. This is because I usually work on my own, and make code that seems self explanatory to me.

    C / C++ / MFC javascript html com graphics debugging

  • vString
    T Tyler Elric

    Okay, I'm new here and new to the community...don't kill me if I seem lazy? I swear I'm not... x) ANYWAYS. Here is a template-abusive custom vector class. It implements buffering, even. (: And Here and here is a custom vString class ( IDK what the 'v' stands for, sorry. Just seemed right. ) I have beat my brains out a few times trying to debug this... Would anybody be willing to help me debug / better organize this code? { Or point out huge problems with it } It just seems really unburly to me, and I'm having a hard time deciding if I should rely on the Vector<>::Add functionality for my vString::Insert() functions ( Append / Prepend are just convenience wrapping functions. I intend to make the vString class operate like jQuery. $().Append($().html("")).Prepend().Remove().Insert() etc ) I will also add support for using glibmm's regex library, but for now, I need to get the basics working out for me. Any help would be much appreciated! :)

    The roof's on fire, but keeps out the rain, so clench your fists and enjoy the pain.

    C / C++ / MFC javascript html com graphics debugging
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups