[CRASH] new char[480MB]

[CRASH] new char[480MB]

Anonymous
Not applicable
360 Views
4 Replies
Message 1 of 5

[CRASH] new char[480MB]

Anonymous
Not applicable
When I attempt to allocate something about 480MB of memory AutoCAD crash
with the following message "Runtime Error! The application has requested the
Runtime to terminate it in an unusual way". So, my question, how to allocate
a large block of memory by ObjectARX application?

Thanks
0 Likes
361 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
This is my working solution to work with big tables in case not enough
contiguous memory.



/*************************************************************************
* START: class HokusVector
*************************************************************************/

template
class HokusVector
{

// typedefs
//

public:
typedef T Value;



// konstruktory / destruktory
//

public:
HokusVector();
~HokusVector();


// operatory
//
public:
Value& operator[](const unsigned int& i);
const Value& operator[](const unsigned int& i) const;


// funkcje uzytkowe
//
public:
void reserve( unsigned int size );
unsigned int size() const;
bool empty() const;
void clear();
void resize( unsigned int size );
void push_back( const T& value );


// dane klasy
//
private:
std::vector< std::vector > m_banks;
unsigned int m_banksize;

};

/*************************************************************************
* END: class HokusVector
*************************************************************************/





/*************************************************************************
* START: class HokusVector
*************************************************************************/

//\\//\\//\\//\\//\\//\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
template
HokusVector::HokusVector()
{ // set
m_banksize = __max( 10, 20000000/sizeof(T) );
}


//\\//\\//\\//\\//\\//\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
template
HokusVector::~HokusVector()
{ //

}


//\\//\\//\\//\\//\\//\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
template HokusVector::Value&
HokusVector::operator[](const unsigned int& i)
{ // success
return m_banks[i/m_banksize][i-(i/m_banksize)*m_banksize];
}


//\\//\\//\\//\\//\\//\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
template const HokusVector::Value&
HokusVector::operator[](const unsigned int& i) const
{ // success
return m_banks[i/m_banksize][i-(i/m_banksize)*m_banksize];
}


//\\//\\//\\//\\//\\//\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
template void
HokusVector::reserve( unsigned int size )
{
// test
if( m_banks.size()*m_banksize >= size )
{ // ERROR: nothing to reserve
return;
}

// resize vectors
m_banks.resize( (size-1 )/m_banksize +1 );

// reserve all vectors
for( unsigned int i=0 ; i { //
m_banks.reserve( m_banksize );
}

}


//\\//\\//\\//\\//\\//\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
template unsigned int
HokusVector::size() const
{

// variables
unsigned int
i, size=0;

// calc
for( i=0 ; i { //
size += m_banks.size();
}

// success
return size;

}


//\\//\\//\\//\\//\\//\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
template bool
HokusVector::empty() const
{
// test
for( unsigned int i=0 ; i {
//
if( !m_banks.empty() )
{ // ERROR: not empty
return false;
}

}

// success: empty
return true;

}


//\\//\\//\\//\\//\\//\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
template void
HokusVector::clear()
{
// clear
for( unsigned int i=0 ; i { //
m_banks.clear();
}

// clear
m_banks.clear();

}


//\\//\\//\\//\\//\\//\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
template void
HokusVector::resize( unsigned int size )
{
// test
if( 0 == size )
{ // just clear
return clear();
}

// resize vectors
m_banks.resize( (size-1)/m_banksize +1 );

// resize all vectors
for( unsigned int i=0 ; i { //
m_banks.resize( m_banksize );
}

// resize last vector
m_banks[m_banks.size()-1].reserve( m_banksize );
m_banks[m_banks.size()-1].resize( size - (m_banks.size()-1)*m_banksize );

}


//\\//\\//\\//\\//\\//\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
template void
HokusVector::push_back( const HokusVector::Value& value )
{
// get size
unsigned int newsize = this->size() +1;

// calc nvectors
unsigned int ivector = (newsize-1) / m_banksize;

// add new vector
if( m_banks.size() <= ivector )
{
//
m_banks.push_back( std::vector() );
m_banks.back().reserve( m_banksize );
assert( m_banks.size() == ivector+1 );
}

// assert
assert( !m_banks.empty() );

// add new item
m_banks[ivector].push_back( value );
assert( m_banks[ivector].size() <= m_banksize );

}


/*************************************************************************
* END: class HokusVector
*************************************************************************/

0 Likes
Message 3 of 5

Anonymous
Not applicable
Why are you using one of std::vector<>, std::deque<> or std::list<>?

Dan

"HokuS" wrote in message
news:[email protected]...
This is my working solution to work with big tables in case not enough
contiguous memory.



/*************************************************************************
* START: class HokusVector
*************************************************************************/

template
class HokusVector
{

// typedefs
//

public:
typedef T Value;



// konstruktory / destruktory
//

public:
HokusVector();
~HokusVector();


// operatory
//
public:
Value& operator[](const unsigned int& i);
const Value& operator[](const unsigned int& i) const;


// funkcje uzytkowe
//
public:
void reserve( unsigned int size );
unsigned int size() const;
bool empty() const;
void clear();
void resize( unsigned int size );
void push_back( const T& value );


// dane klasy
//
private:
std::vector< std::vector > m_banks;
unsigned int m_banksize;

};

/*************************************************************************
* END: class HokusVector
*************************************************************************/





/*************************************************************************
* START: class HokusVector
*************************************************************************/

//\\//\\//\\//\\//\\//\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
template
HokusVector::HokusVector()
{ // set
m_banksize = __max( 10, 20000000/sizeof(T) );
}


//\\//\\//\\//\\//\\//\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
template
HokusVector::~HokusVector()
{ //

}


//\\//\\//\\//\\//\\//\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
template HokusVector::Value&
HokusVector::operator[](const unsigned int& i)
{ // success
return m_banks[i/m_banksize][i-(i/m_banksize)*m_banksize];
}


//\\//\\//\\//\\//\\//\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
template const HokusVector::Value&
HokusVector::operator[](const unsigned int& i) const
{ // success
return m_banks[i/m_banksize][i-(i/m_banksize)*m_banksize];
}


//\\//\\//\\//\\//\\//\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
template void
HokusVector::reserve( unsigned int size )
{
// test
if( m_banks.size()*m_banksize >= size )
{ // ERROR: nothing to reserve
return;
}

// resize vectors
m_banks.resize( (size-1 )/m_banksize +1 );

// reserve all vectors
for( unsigned int i=0 ; i { //
m_banks.reserve( m_banksize );
}

}


//\\//\\//\\//\\//\\//\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
template unsigned int
HokusVector::size() const
{

// variables
unsigned int
i, size=0;

// calc
for( i=0 ; i { //
size += m_banks.size();
}

// success
return size;

}


//\\//\\//\\//\\//\\//\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
template bool
HokusVector::empty() const
{
// test
for( unsigned int i=0 ; i {
//
if( !m_banks.empty() )
{ // ERROR: not empty
return false;
}

}

// success: empty
return true;

}


//\\//\\//\\//\\//\\//\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
template void
HokusVector::clear()
{
// clear
for( unsigned int i=0 ; i { //
m_banks.clear();
}

// clear
m_banks.clear();

}


//\\//\\//\\//\\//\\//\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
template void
HokusVector::resize( unsigned int size )
{
// test
if( 0 == size )
{ // just clear
return clear();
}

// resize vectors
m_banks.resize( (size-1)/m_banksize +1 );

// resize all vectors
for( unsigned int i=0 ; i { //
m_banks.resize( m_banksize );
}

// resize last vector
m_banks[m_banks.size()-1].reserve( m_banksize );
m_banks[m_banks.size()-1].resize( size - (m_banks.size()-1)*m_banksize );

}


//\\//\\//\\//\\//\\//\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
template void
HokusVector::push_back( const HokusVector::Value& value )
{
// get size
unsigned int newsize = this->size() +1;

// calc nvectors
unsigned int ivector = (newsize-1) / m_banksize;

// add new vector
if( m_banks.size() <= ivector )
{
//
m_banks.push_back( std::vector() );
m_banks.back().reserve( m_banksize );
assert( m_banks.size() == ivector+1 );
}

// assert
assert( !m_banks.empty() );

// add new item
m_banks[ivector].push_back( value );
assert( m_banks[ivector].size() <= m_banksize );

}


/*************************************************************************
* END: class HokusVector
*************************************************************************/

0 Likes
Message 4 of 5

Anonymous
Not applicable
When I attempt to call std::vector::reserve(480000000) or
std::list::resize(480000000) CRASH occurs. Do you think 480MB is too
much for ObjectARX applications? Of course no, when I use my vector class
everything is fine and I am able to allocate more than 1GB of memory.

Regards
0 Likes
Message 5 of 5

Anonymous
Not applicable
When I try
malloc(480 * 1024 * 1024);
I get a "CAcadMemoryException"

In a 'normal' environment I can allocate 2 G's
(And aCad itself eats only about 50Mb's)

So maybe you should allocate large chunk in a
separate thread
0 Likes