本文整理汇总了C++中onmalloc函数的典型用法代码示例。如果您正苦于以下问题:C++ onmalloc函数的具体用法?C++ onmalloc怎么用?C++ onmalloc使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了onmalloc函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onmalloc
void* ON_Workspace::GetMemory( size_t size )
{
void* p = NULL;
if ( size > 0 )
{
struct ON_Workspace_MBLK* pBlk = (struct ON_Workspace_MBLK*)onmalloc(sizeof(*pBlk));
if ( pBlk )
{
pBlk->pMem = p = onmalloc(size);
pBlk->pNext = m_pMemBlk;
m_pMemBlk = pBlk;
}
}
return p;
}
示例2: Destroy
bool ON_Matrix::Create( int row_count, int col_count)
{
bool b = false;
Destroy();
if ( row_count > 0 && col_count > 0 )
{
m_rowmem.Reserve(row_count);
if ( 0 != m_rowmem.Array() )
{
m_rowmem.SetCount(row_count);
// In general, allocate coefficient memory in chunks
// of <= max_dblblk_size bytes. The value of max_dblblk_size
// is tuned to maximize speed on calculations involving
// large matrices. If all of the coefficients will fit
// into a chunk of memory <= 1.1*max_dblblk_size, then
// a single chunk is allocated.
// In limited testing, these two values appeared to work ok.
// The latter was a hair faster in solving large row reduction
// problems (for reasons I do not understand).
//const int max_dblblk_size = 1024*1024*8;
const int max_dblblk_size = 512*1024;
int rows_per_block = max_dblblk_size/(col_count*sizeof(double));
if ( rows_per_block > row_count )
rows_per_block = row_count;
else if ( rows_per_block < 1 )
rows_per_block = 1;
else if ( rows_per_block < row_count && 11*rows_per_block >= 10*row_count )
rows_per_block = row_count;
int j, i = row_count;
m = m_rowmem.Array();
double** row = m;
for ( i = row_count; i > 0; i -= rows_per_block )
{
if ( i < rows_per_block )
rows_per_block = i;
int dblblk_count = rows_per_block*col_count;
struct DBLBLK* p = (struct DBLBLK*)onmalloc(sizeof(*p) + dblblk_count*sizeof(p->a[0]));
p->a = (double*)(p+1);
p->count = dblblk_count;
p->next = (struct DBLBLK*)m_cmem;
m_cmem = p;
*row = p->a;
j = rows_per_block-1;
while(j--)
{
row[1] = row[0] + col_count;
row++;
}
row++;
}
m_row_count = row_count;
m_col_count = col_count;
b = true;
}
}
return b;
}
示例3: Evaluate
ON_3dPoint ON_BezierCage::PointAt( ON_3dPoint rst ) const
{
ON_3dPoint pt;
if ( m_dim <= 3 )
{
pt.x = 0.0;
pt.y = 0.0;
pt.z = 0.0;
Evaluate(rst.x,rst.y,rst.z,0,3,&pt.x);
}
else
{
double stack_buffer[16];
double* v;
size_t sizeof_buffer = m_dim*sizeof(*v);
v = (sizeof_buffer <= sizeof(stack_buffer)) ? stack_buffer : (double*)onmalloc(sizeof_buffer);
v[0] = 0.0;
v[1] = 0.0;
v[2] = 0.0;
Evaluate(rst.x,rst.y,rst.z,0,m_dim,v);
pt.x = v[0];
pt.y = v[1];
pt.z = v[2];
if ( v != stack_buffer )
onfree(v);
}
return pt;
}
示例4: SpanCount
//Do not change SpanCount() without making sure it gives the correct result for use in GetSpanVector()
int ON_CurveProxy::SpanCount() const
{
if (!m_real_curve) return 0;
int rsc = m_real_curve->SpanCount();
ON_Interval domain = m_real_curve->Domain();
if (m_real_curve_domain == domain)
return rsc;
double* rsv = (double*)onmalloc((rsc+1)*sizeof(double));
if (!rsv) return 0;
if (!m_real_curve->GetSpanVector(rsv)){
onfree((void*)rsv);
return 0;
}
int i=0;
int sc = 0;
while (i <= rsc && rsv[i] <= m_real_curve_domain[0]) i++;
while (i <= rsc && rsv[i] < m_real_curve_domain[1]){
sc++;
i++;
}
sc++;
onfree((void*)rsv);
return sc;
}
示例5: AddNgon
struct ON_MeshNgon* ON_MeshNgonList::AddNgon(int N)
{
if ( N < 3 || N > 100000 )
return 0;
if ( m_ngons_count >= m_ngons_capacity )
{
int capacity = 2*m_ngons_count;
if (capacity < m_ngons_count+16)
capacity = m_ngons_count+16;
if ( !ReserveNgonCapacity(capacity) )
return 0;
}
ON_MeshNgon& ngon = m_ngons[m_ngons_count++];
ngon.N = N;
struct ON_NGON_MEMBLK* blk = (struct ON_NGON_MEMBLK*)onmalloc(sizeof(*blk) + (2*N)*sizeof(int));
if ( 0 == blk )
return 0;
ngon.vi = (int*)(blk + 1);
ngon.fi = ngon.vi + N;
memset(ngon.vi,0xFF,(2*N)*sizeof(int)); // set all indicies to -1
blk->next = m_memblk_list;
m_memblk_list = blk;
return &ngon;
}
示例6: onmalloc
void* ON_Object::operator new[] (size_t sz)
{
// ON_Object array new
// The else "sz?sz:1" is there because section 3.7.3.1,
// paragraph 2 of the C++ "standard" says something along
// the lines of:
//
// The function shall return the address of the start of a
// block of storage whose length in bytes shall be at least
// as large as the requested size. There are no constraints
// on the contents of the allocated storage on return from
// the allocation function. The order, contiguity, and initial
// value of storage allocated by successive calls to an
// allocation function is unspecified. The pointer returned
// shall be suitably aligned so that it can be converted to a
// pointer of any complete object type and then used to
// access the object or array in the storage allocated (until
// the storage is explicitly deallocated by a call to a
// corresponding deallocation function). If the size of the
// space requested is zero, the value returned shall not be a
// null pointer value. The results of dereferencing a pointer
// returned as a request for zero size are undefined.
return onmalloc(sz?sz:1);
}
示例7: SpanCount
//////////
// If t is in the domain of the surface, GetSpanVectorIndex() returns the
// span vector index "i" such that span_vector[i] <= t <= span_vector[i+1].
// The "side" parameter determines which span is selected when t is at the
// end of a span.
//
//virtual
ON_BOOL32 ON_Surface::GetSpanVectorIndex(
int dir, // 0 gets first parameter's domain, 1 gets second parameter's domain
double t, // [IN] t = evaluation parameter
int side, // [IN] side 0 = default, -1 = from below, +1 = from above
int* span_vector_i, // [OUT] span vector index
ON_Interval* span_domain // [OUT] domain of the span containing "t"
) const
{
ON_BOOL32 rc = false;
int i;
int span_count = SpanCount(dir);
if ( span_count > 0 ) {
double* span_vector = (double*)onmalloc((span_count+1)*sizeof(span_vector[0]));
rc = GetSpanVector( dir, span_vector );
if (rc) {
i = ON_NurbsSpanIndex( 2, span_count, span_vector, t, side, 0 );
if ( i >= 0 && i <= span_count ) {
if ( span_vector_i )
*span_vector_i = i;
if ( span_domain )
span_domain->Set( span_vector[i], span_vector[i+1] );
}
else
rc = false;
}
onfree(span_vector);
}
return rc;
}
示例8: onfree
bool ON_CompressStream::Begin()
{
if ( 0 != m_implementation )
{
onfree(m_implementation);
m_implementation = 0;
}
// zero these because the same instance of an
// ON_CompressStream class may be used multiple times.
m_in_size = 0;
m_out_size = 0;
m_in_crc = 0;
m_out_crc = 0;
struct ON_ZlibImplementation* imp = (struct ON_ZlibImplementation*)onmalloc(sizeof(*imp));
memset(&imp->m_strm,0,sizeof(imp->m_strm));
if ( Z_OK != deflateInit( &imp->m_strm, Z_BEST_COMPRESSION ) )
{
onfree(imp);
return false;
}
m_implementation = imp;
return true;
}
示例9: RhinoApp
CRhinoCommand::result CCommandSampleTriangulatePolygon::RunCommand( const CRhinoCommandContext& context )
{
CRhinoGetObject go;
go.SetCommandPrompt( L"Select closed planar polygon to triangulate" );
go.SetGeometryFilter( CRhinoGetObject::curve_object );
go.SetGeometryFilter( CRhinoGetObject::closed_curve );
go.EnableSubObjectSelect( FALSE );
go.GetObjects( 1, 1 );
if( go.CommandResult() != CRhinoCommand::success )
return go.CommandResult();
const CRhinoObjRef& ref = go.Object(0);
ON_3dPointArray vertices;
const ON_PolylineCurve* pc = ON_PolylineCurve::Cast( ref.Curve() );
if( pc )
{
vertices = pc->m_pline;
}
else
{
const ON_NurbsCurve* nc = ON_NurbsCurve::Cast( ref.Curve() );
if( nc )
nc->IsPolyline( &vertices );
}
if( vertices.Count() < 5 )
{
RhinoApp().Print( L"Curve not polygon with at least four sides.\n" );
return CRhinoCommand::nothing;
}
int* triangles = (int*)onmalloc( (vertices.Count()-3) * sizeof(int) * 3 );
if( 0 == triangles )
return CRhinoCommand::failure; // out of memory
memset( triangles, 0, (vertices.Count()-3) * sizeof(int) * 3 );
int rc = RhinoTriangulate3dPolygon( vertices.Count()-1, 3, (const double*)vertices.Array(), 3, triangles);
if( 0 == rc )
{
int i;
for( i = 0; i < vertices.Count()-3; i++ )
{
ON_Polyline pline;
pline.Append( vertices[triangles[i * 3]] );
pline.Append( vertices[triangles[i * 3 + 1]] );
pline.Append( vertices[triangles[i * 3 + 2]] );
pline.Append( pline[0] );
context.m_doc.AddCurveObject( pline );
}
context.m_doc.Redraw();
}
onfree( triangles );
return CRhinoCommand::success;
}
示例10: ThisM
int
ON_Matrix::RowReduce(
double zero_tolerance,
ON_3dPoint* B,
double* pivot
)
{
ON_3dPoint t;
double x, piv;
int i, k, ix, rank;
double** this_m = ThisM();
piv = 0.0;
rank = 0;
const int n = m_row_count <= m_col_count ? m_row_count : m_col_count;
for ( k = 0; k < n; k++ ) {
//onfree( onmalloc( 1)); // 8-06-03 lw for cancel thread responsiveness
onmalloc( 0); // 9-4-03 lw changed to 0
ix = k;
x = fabs(this_m[ix][k]);
for ( i = k+1; i < m_row_count; i++ ) {
if ( fabs(this_m[i][k]) > x ) {
ix = i;
x = fabs(this_m[ix][k]);
}
}
if ( x < piv || k == 0 ) {
piv = x;
}
if ( x <= zero_tolerance )
break;
rank++;
// swap rows of matrix and B
SwapRows( ix, k );
t = B[ix]; B[ix] = B[k]; B[k] = t;
// scale row k of matrix and B
x = 1.0/this_m[k][k];
this_m[k][k] = 1.0;
ON_ArrayScale( m_col_count - 1 - k, x, &this_m[k][k+1], &this_m[k][k+1] );
B[k] *= x;
// zero column k for rows below this_m[k][k]
for ( i = k+1; i < m_row_count; i++ ) {
x = -this_m[i][k];
this_m[i][k] = 0.0;
if ( fabs(x) > zero_tolerance ) {
ON_Array_aA_plus_B( m_col_count - 1 - k, x, &this_m[k][k+1], &this_m[i][k+1], &this_m[i][k+1] );
B[i] += x*B[k];
}
}
}
if ( pivot )
*pivot = piv;
return rank;
}
示例11: ON_SolveSVD
bool ON_SolveSVD(
int row_count,
int col_count,
double const * const * U,
const double* invW,
double const * const * V,
const double* B,
double*& X
)
{
int i, j;
double *Y;
const double* p0;
double workY[128], x;
if ( row_count < 1 || col_count < 1 || 0 == U || 0 == invW || 0 == V || 0 == B)
return false;
if ( 0 == X )
X = (double*)onmalloc(col_count*sizeof(X[0]));
Y = (col_count > 128)
? ( (double*)onmalloc(col_count*sizeof(*Y)) )
: workY;
for (i = 0; i < col_count; i++)
{
double y = 0.0;
for (j = 0; j < row_count; j++)
y += U[j][i] * *B++;
B -= row_count;
Y[i] = invW[i] * y;
}
for (i = 0; i < col_count; i++)
{
p0 = V[i];
j = col_count;
x = 0.0;
while (j--)
x += *p0++ * *Y++;
Y -= col_count;
X[i] = x;
}
if (Y != workY)
onfree(Y);
return true;
}
示例12: onmalloc
bool ON_CompressedBuffer::Read( ON_BinaryArchive& binary_archive )
{
int major_version = 0;
int minor_version = 0;
bool rc = binary_archive.BeginRead3dmChunk(TCODE_ANONYMOUS_CHUNK,&major_version,&minor_version);
if ( !rc )
return false;
for(;;)
{
rc = ( 1 == major_version );
if ( !rc )
break;
rc = binary_archive.ReadSize(&m_sizeof_uncompressed);
if (!rc)
break;
rc = binary_archive.ReadSize(&m_sizeof_compressed);
if (!rc)
break;
rc = binary_archive.ReadInt(&m_crc_uncompressed);
if (!rc)
break;
rc = binary_archive.ReadInt(&m_crc_compressed);
if (!rc)
break;
rc = binary_archive.ReadInt(&m_method);
if (!rc)
break;
rc = binary_archive.ReadInt(&m_sizeof_element);
if (!rc)
break;
if ( m_sizeof_compressed > 0 )
{
m_buffer_compressed = onmalloc(m_sizeof_compressed);
if ( m_buffer_compressed )
{
m_buffer_compressed_capacity = m_sizeof_compressed;
rc = binary_archive.ReadByte(m_sizeof_compressed,m_buffer_compressed);
}
else
{
m_sizeof_compressed =0;
}
if (!rc)
break;
}
break;
}
if ( !binary_archive.EndRead3dmChunk() )
rc = false;
return rc;
}
示例13: hint
ON_BOOL32
ON_Surface::Ev1Der( // returns false if unable to evaluate
double s, double t, // evaluation parameters
ON_3dPoint& point,
ON_3dVector& ds,
ON_3dVector& dt,
int side, // optional - determines which side to evaluate from
// 0 = default
// 1 from NE quadrant
// 2 from NW quadrant
// 3 from SW quadrant
// 4 from SE quadrant
int* hint // optional - evaluation hint (int[2]) used to speed
// repeated evaluations
) const
{
ON_BOOL32 rc = false;
const int dim = Dimension();
double ws[3*32];
double* v;
point.x = 0.0;
point.y = 0.0;
point.z = 0.0;
ds.x = 0.0;
ds.y = 0.0;
ds.z = 0.0;
dt.x = 0.0;
dt.y = 0.0;
dt.z = 0.0;
if ( dim <= 32 ) {
v = ws;
}
else {
v = (double*)onmalloc(3*dim*sizeof(*v));
}
rc = Evaluate( s, t, 1, dim, v, side, hint );
point.x = v[0];
ds.x = v[dim];
dt.x = v[2*dim];
if ( dim > 1 ) {
point.y = v[1];
ds.y = v[dim+1];
dt.y = v[2*dim+1];
if ( dim > 2 ) {
point.z = v[2];
ds.z = v[dim+2];
dt.z = v[2*dim+2];
if ( dim > 32 )
onfree(v);
}
}
return rc;
}
示例14: w2c_size
void ON_String::CopyToArray( int w_count, const wchar_t* w )
{
// convert UTF-16 string to UTF-8 string
int c_count = w2c_size( w_count, w );
char* c = (char*)onmalloc(c_count+1);
memset( c, 0, c_count+1 );
const int c_length = w2c( w_count, w, c_count, c );
c[c_length] = 0;
CopyToArray( c_count, c );
onfree(c);
}
示例15: Create
ON_wString::ON_wString( unsigned char c, int repeat_count )
{
Create();
if ( repeat_count > 0 ) {
char* s = (char*)onmalloc((repeat_count+1)*sizeof(*s));
s[repeat_count] = 0;
memset( s, c, repeat_count*sizeof(*s) );
CopyToArray( repeat_count, s );
onfree(s);
m_s[repeat_count] = 0;
Header()->string_length = repeat_count;
}
}