Halsafar's Cpp SLAQ Library-VBForums
Results 1 to 8 of 8

Thread: Halsafar's Cpp SLAQ Library

  1. #1

    Thread Starter
    PowerPoster Halsafar's Avatar
    Join Date
    Jun 2004
    Location
    Saskatoon, SK
    Posts
    2,339

    Halsafar's Cpp SLAQ Library

    SLAQ - Stack, List, Array, Queue
    Sound it out -- C++ Slaq - Slack -- Easy

    Unfortunatly the list and queue have not been included, but the abstract SLAQ class has been included with two derives, Stack and Array. The List is a managed list which uses a stack of free_id's to allow very quick insertion, in fact up to the 50,000 index mark it is incredibly fast it is due to this fact I have not included it.

    The app_Main.cpp includes a small benchmark which runs a console app, asks the allocation size and does a comparison: Hals Array VS std::vector. It compares the alike push_backs functions and plain assigments.

    On my computer the assigment match ties at exactly 20 indices. Anything less than 20 and vector seems to win, anything above 20 and my array seems to make very large jumps. The push_back match acts much the same except they seem to stay pretty close even though mine does jump ahead.

    Unfortunetly, a RELEASE mode compile completly changes everything -- the assigment match will almost ALWAYS be won by Hals Dynamic Array, where on the other hand the push_back() match will always been won by vector.

    A last note, this is not even close to version 1.0 of this release and it is really meant for games. In fact the managed list, in release mode, can process 50,000 push's faster than anything I've seen, but it is a list method where you do not need to know the precise location of your members (a unit pool for example). The library will eventually be out for full release and I hope to get that release mode push_back to fight harder. Most of this stuff is pretty basic, but it does show a use of complex memory managment combining both some C and C++ functions.


    Thanks for downloading, please leave you comments.
    If you wish to incorporate any of this code then just allow me the honor of knowing where it is being used and by who otherwise I have no objections.
    Halsafar
    Attached Files Attached Files
    "From what was there, and was meant to be, but not of that was faded away." - - Steve Damm

    "The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm

    "When you do things right, people won't be sure if you did anything at all." - - God from Futurama

  2. #2
    Frenzied Member aewarnick's Avatar
    Join Date
    Dec 2002
    Posts
    1,037

    Re: Halsafar's Cpp SLAQ Library

    memset is slow compared to memcpy
    This was in your ReAlloc function:

    if (uiSize > m_dwMaxIndex) { //If we are enlarging the array then we must set to 0
    memset(m_Begin+m_dwMaxIndex, 0, m_SizeOf * (uiSize-m_dwMaxIndex));

    I can't see it as being really necessary, I think you should remove it.

  3. #3

    Thread Starter
    PowerPoster Halsafar's Avatar
    Join Date
    Jun 2004
    Location
    Saskatoon, SK
    Posts
    2,339

    Re: Halsafar's Cpp SLAQ Library

    Not necessary but it initializes all indices to 0.
    If memcpy does it faster then beautiful.

    I noticed a big difference from your to mine was the fact I used malloc and realloc. You use new and had to temp the array, create a new array, copy the old, delete the old. This is all elimated with realloc.
    "From what was there, and was meant to be, but not of that was faded away." - - Steve Damm

    "The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm

    "When you do things right, people won't be sure if you did anything at all." - - God from Futurama

  4. #4
    Frenzied Member aewarnick's Avatar
    Join Date
    Dec 2002
    Posts
    1,037

    Re: Halsafar's Cpp SLAQ Library

    Yes, I looked into realloc and figured that out but that was not the major performance hit. It was Resizing only by 10 each time instead of by .2f.

    I probably need to stick with new delete because I probably will have destructors and constructors that need called.

  5. #5

    Thread Starter
    PowerPoster Halsafar's Avatar
    Join Date
    Jun 2004
    Location
    Saskatoon, SK
    Posts
    2,339

    Re: Halsafar's Cpp SLAQ Library

    What do you mean constructors/destructors which require new??
    I have found that malloc and new --- free and delete are pretty well the exact same and can be used in any situation. It is usually a point of preference -- also if you need to resize a lot without data loss then malloc/realloc is your BEST choice.
    Just never mix a malloc allocation with delete
    "From what was there, and was meant to be, but not of that was faded away." - - Steve Damm

    "The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm

    "When you do things right, people won't be sure if you did anything at all." - - God from Futurama

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: Halsafar's Cpp SLAQ Library

    Do you want comments on the code? Be warned, they would be harsh.

    (Correction: after looking at the code a little bit, I must say that they would be very harsh.)
    Last edited by CornedBee; Mar 9th, 2005 at 05:01 PM.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  7. #7
    Frenzied Member aewarnick's Avatar
    Join Date
    Dec 2002
    Posts
    1,037

    Re: Halsafar's Cpp SLAQ Library

    CLICK
    I'll give it a try though because I really did want to use realloc.

  8. #8

    Thread Starter
    PowerPoster Halsafar's Avatar
    Join Date
    Jun 2004
    Location
    Saskatoon, SK
    Posts
    2,339

    Re: Halsafar's Cpp SLAQ Library

    Whats wrong with the code?
    I expect some critism, how else do I find my flaws.
    Programming has habits, often bad ones as habits tend to be.
    "From what was there, and was meant to be, but not of that was faded away." - - Steve Damm

    "The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm

    "When you do things right, people won't be sure if you did anything at all." - - God from Futurama

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.