Raised This Month: $ Target: $400
 0% 

Can someone test my c++ code?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
aron9forever
Veteran Member
Join Date: Feb 2013
Location: Rromania
Old 05-15-2015 , 14:10   Re: Can someone test my c++ code?
Reply With Quote #1

if you package everything inside an archive I can run it for you under codeblocks (mingw) XP 32bit
__________________
Meanwhile, in 2050:
Quote:
Originally Posted by aron9forever
useless small optimizations
Quote:
Originally Posted by Black Rose View Post
On a map that is 512x512x128 units you end up with 3,355,443,200,000 different "positions". To store each one of those positions individually in the variable "user_or" you need 12 terabytes of memory.
aron9forever is offline
Gyiove
BANNED
Join Date: May 2015
Location: Wait, where am i again?
Old 05-15-2015 , 14:14   Re: Can someone test my c++ code?
Reply With Quote #2

Quote:
Originally Posted by aron9forever View Post
if you package everything inside an archive I can run it for you under codeblocks (mingw) XP 32bit
PHP Code:
#include <stdio.h> 
#include <iostream> 
#include <fstream> 
#include <windows.h> 
#include <vector> 

template <class T
class 
spvec 

public: 
    
*data
    
int size
    
int reserved
    
int reservstep
    
float reservstep_grow

    
spvec() 
    { 
        
size 0
        
reserved 0
        
reservstep 1
        
data 0
        
reservstep_grow 1.5f
    } 

    
spvec(int reservstep
    { 
        
size 0
        
reserved 0
        
reservstep reservstep
        
data 0
        
reservstep_grow 0.0f
    } 

    
spvec(*indataint insize
    { 
        
size insize
        
reserved 0
        
reservstep 1
        
data indata
        
reservstep_grow 1.5f
    } 

    
spvec(*indataint insizeint reservstep
    { 
        
size insize
        
reserved 0
        
reservstep reservstep
        
data indata
        
reservstep_grow 0.0f
    } 

    ~
spvec() 
    { 
        if( 
size || reserved delete [] data
    } 

    
void destroy() 
    { 
        
size 0
        
reserved 0
        
delete [] data
    } 

    
void makeroom(int howmuch
    { 
        if (
reservstep_grow 1.0reservstep int((float)size reservstep_grow); 
        
*= new T[size+reserved+howmuch+reservstep]; 
        for( 
int a 0sizea++ ) p[a] = data[a]; 
        if(
sizedelete [] data
        
data p
        
reserved += howmuch reservstep
    } 

    
void takeroomint howmuch 
    { 
        
int needs reserved howmuch
        if( 
needs makeroom(needs / -1); 
        
size += howmuch
        
reserved -= howmuch
    } 

    
void trim() 
    { 
        
*= new T[size+reservstep]; 
        for( 
int a 0sizea++ ) p[a] = data[a]; 
        if(
sizedelete [] data
        
data p
        
reserved reservstep
    } 

    
void remove(int pos
    { 
        
reserved++; 
        for( 
int a possize 1a++ ) data[a] = data[a+1]; 
        
size--; 
    } 

    
void remove(int posint howmuch
    { 
        
reserved += howmuch
        for( 
int a possize 1a++ ) data[a] = data[a+howmuch]; 
        
size -= howmuch
    } 

    
void reverse() 
    { 
        
T temp
        
int v 0
        for( 
int a 0size 2a++ )  
        { 
            
size - (1); 
            
temp data[a]; 
            
data[a] = data[v]; 
            
data[v] = temp
        } 
    } 

    
void clear() 
    { 
        
reserved += size
        
size 0
    } 

    
void resize(int newsize
    { 
        if (
newsize == 0
        { 
            
clear(); 
            return; 
        } 
        
= new T[newsize reservstep]; 
        
int b size
        if (
newsize sizenewsize

        if (
b) for (int a 0ba++) t[a] = data[a]; 
        if (
sizedelete[] data
        
size b
        
data t
    } 

    
void moveint whatint to 
    { 
        
int aT temp
        if( 
what to 
        { 
            
temp data[what]; 
            for( 
whattoa-- ) data[a] = data[a-1]; 
            
data[to] = temp
            return; 
        } 

        
temp data[what]; 
        for( 
whattoa++ ) 
        { 
            
data[a] = data[a+1]; 
        } 
        
data[to] = temp
    } 

    
void moveint whatint howmuchint to 
    { 
        
howmuch--; 
        if( 
what to 
        { 
            for( 
int a 0<= howmucha++ ) move(what howmuchto); 
            return; 
        } 
        for( 
int a 0<= howmucha++ ) move(whatto howmuch); 
    } 


    
void pushT in 
    { 
        
takeroom); 
        
data[size 1] = in
    } 

    
void pushint posT in 
    { 
        
takeroom(1); 
        for( 
int a size 2>= posa-- ) data[1] = data[a]; 
        
data[pos] = in
    } 

    
void push(*inint insize
    { 
        
int i size
        
takeroom(insize); 
        for (
int a 0insizea++) data[a] = in[a]; 
    } 

    
void push(int pos*inint insize
    { 
        
int i size
        
takeroom(insize); 
        
int a
        for (
size 2>= posa--) data[insize] = data[a]; 
        for (
posinsizea++) data[a] = in[pos]; 
    } 

    
void swap(int whatint with
    { 
        
T t
        
data[what]; 
        
data[what] = data[with]; 
        
data[with] = t
    } 

    
void swap(int startint endint to
    { 
        for (
int a 0end starta++) swap(start ato a); 
    } 

    const 
spvec &operator+=(const spvec <Tin
    { 
        if (!
in.size) return (*this); 
        
this->push(in.datain.size); 
        return (*
this); 
    } 

    const 
spvec &operator-=(const spvec <Tin
    { 
        if (!
in.size) return (*this); 
        
this->push(0in.datain.size); 
        return (*
this); 
    } 

    const 
spvec &operator+=(const T in
    { 
        
this->push(in); 
        return (*
this); 
    } 

    const 
spvec &operator%=(int in
    { 
        
this->resize(in); 
        return (*
this); 
    } 

    const 
spvec &operator-=(const int in
    { 
        
this->push(0in); 
        return (*
this); 
    } 


    const 
spvec &operator=(int in
    { 
        
this->resize(in); 
        return (*
this); 
    } 


    
&operator[](int in) const 
    { 
        return (*(
this->data in)); 
    } 


    
spvec(spvec <T> &in
    { 
        
cout << "here1" << endl
        if (
this == &in
        { 
            
cout << "this == &in" << endl
            return; 
        } 
        
this->size in.size
        
this->reserved in.reserved
        
this->reservstep in.reservstep
        if (
in.size || in.reserved
        { 
            
this->data = new T[in.size in.reserved]; 
            for (
int a 0in.sizea++) this->data[a] = in.data[a]; 
        } 
    } 

    const 
spvec <T> &operator=(const spvec <T> &in
    { 
        
cout << "here2" << endl
        if (
this == &in
        { 
            
cout << "this == &in" << endl
            return (*
this); 
        } 

        if (
this->size
        { 
            
cout << "clear old" << endl
            
delete[] this->data
        } 
        
this->size in.size
        
this->reserved in.reserved
        
this->reservstep in.reservstep
        if (
in.size || in.reserved
        { 
            
this->data = new T[in.size in.reserved]; 
            for (
int a 0in.sizea++) this->data[a] = in.data[a]; 
        } 
        return (*
this); 
    } 
};  


LARGE_INTEGER t_start_countert_current_counter
void tstart() 

    
QueryPerformanceCounter(&t_start_counter); 


double tend() 

    
QueryPerformanceCounter(&t_current_counter); 
    
double out
    
out = (double)(t_current_counter.QuadPart t_start_counter.QuadPart); 
    
out *= 0.000001
    return 
out


int _tmain(int argc_TCHARargv[]) 


    
int a 00
    
spvec<intv


    
vector<inti
    
double t1 0.0t2 0.0
    
v.reservstep_grow 3.0f


    
tstart(); 
    for (
016777216a++) += 100
    
t1 tend(); 

    
tstart(); 
    for (
016777216a++) i.push_back(100); 
    
t2 tend(); 

    
cout << "myvector/defaultvector" << endl
    
cout << "reserved:" << v.reservstep << "/" << i.capacity() << endl
    
cout << "size:" << v.size  << "/" << i.size() << endl
    
cout << "times:" << t1 << "/" << t2 << " ration:" << t2 t1 << endl
     
    
system("pause"); 
    return 
0

just copy and paste the whole code and it should run fine.
Unless you're using linux...
Gyiove is offline
Send a message via Skype™ to Gyiove
aron9forever
Veteran Member
Join Date: Feb 2013
Location: Rromania
Old 05-15-2015 , 14:29   Re: Can someone test my c++ code?
Reply With Quote #3

here u go
__________________
Meanwhile, in 2050:
Quote:
Originally Posted by aron9forever
useless small optimizations
Quote:
Originally Posted by Black Rose View Post
On a map that is 512x512x128 units you end up with 3,355,443,200,000 different "positions". To store each one of those positions individually in the variable "user_or" you need 12 terabytes of memory.
aron9forever is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 01:17.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode