DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3

Hybrid View

  1. #1
    Join Date
    Jul 2004
    Posts
    1

    Default value Initialization

    Hi there
    After creating a twodimensional array of the form

    double** psimilarity = new double*[doccount];
    for (int i = 0; i < doccount ; ++i)
    psimilarity[i] = new double[doccount];
    similarity = psimilarity;

    VC++.Net initializes every arrayvalue with the same value to the power of minus 63. But my goal is to have every value being initialized to 0.0.
    I tried

    memset(similarity,0,sizeof(double)*doccount*doccount);

    but then the programm crashes half the time.

    I should point out, that the programm is very performance sensitive (wich isnt :rolleyes: )

    Thank you

  2. #2
    Join Date
    Jun 2004
    Location
    canada
    Posts
    27
    i'm not sure i understand what you asking for, but what i think is you want to set every index of the array to the same memory location? if that is what you are trying to do it is impossible. it defies the logic of how an array works. the index increments along the bits based on the size of the datatype definition for that array. index 3 for instance would be (3 *double), and would increment that many bits from the array pointer initial memory address. otherwise i don't understand what you are asking and i apologize for wasting your time.
    the virtuous lead with their minds.

  3. #3
    Join Date
    Nov 2003
    Posts
    4,118
    people hate it when I say this, but if you want to allocate an array and make sure that it's zero initialized, use calloc(), not new. calloc ensures zero-initialization of the allocated elements. Of course, use free() to release it afterwards.
    Danny Kalev

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links