Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8771295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:44:58+00:00 2026-06-13T17:44:58+00:00

And peformance-wise, are there some better ways to do that? for example, create a

  • 0

And peformance-wise, are there some better ways to do that?

for example, create a class/struct called arraydata, it allocates some aligned memory for use (though a pointer provided by .dataPtr):

class arraydata//to allocate some memory, 
               //and return a pointer to that block of memory
{
    void *dataPtrV;

  public:

    double *dataPtr;

    arraydata(int a, int b)
    {
        dataPtrV=_aligned_malloc(a*b*sizeof(double),32);
        dataPtr=(double *)dataPtrV;
    }

    ~arraydata()
    {
        _aligned_free(dataPtrV);
        dataPtrV=NULL;
        dataPtr=NULL;
    }   
};

Then call it by:

     arraydata X(30,20);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T17:44:59+00:00Added an answer on June 13, 2026 at 5:44 pm

    Yes, that would be considered RAII – the resource is acquired in the constructor and released in the destructor.

    I’m not sure why you’re storing both a void* and a double* though – only a double* should suffice.

    Also, be extremely careful when copying your class as that will easily lead to leaks and freeing already freed data.

    Anyway, this can also be done using std::unique_ptr which is more idiomatic and without the downfalls of your class:

    struct aligned_free {
      void operator()(void* p) {
         _aligned_free(p);
      }
    };
    
    template<typename T>
    T* aligned_malloc(std::size_t size, std::size_t alignment) {
      return static_cast<T*>(_aligned_malloc(size * sizeof(T), alignment));
    }
    
    std::unique_ptr<double, aligned_free> make_array_data(int a, int b) {
        return std::unique_ptr<double, aligned_free>(aligned_malloc<double>(a*b, 32));
    }
    
    auto arraydata = make_array_data(30, 20);
    

    Here’s your class without void*:

    class arraydata//to allocate some memory, 
                   //and return a pointer to that block of memory
    {
    
      public:
    
        double *dataPtr;
    
        arraydata(int a, int b)
        {
            dataPtr=static_cast<double*>(_aligned_malloc(a*b*sizeof(double),32));
        }
    
        ~arraydata()
        {
            _aligned_free(dataPtr);
        }   
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For performance wise, some people suggest use the following method, e.g. public class MyActivity
Is there an advantage of some sort (speed or performance wise) to embed your
I'm wondering if there is a difference performance wise between using COUNT(*) and COUNT(date_created)
Is there any difference in performance ( speed wise ) between a synchronous request
What is better for performance wise declaring the variable outside the foreach statment and
OK here's the deal. There are some people who put their lives in the
For example, let's say there is a custom template tag {% custom_tag parameter %}
I've heard from some that LINQ to SQL is good for lightweight apps. But
I've seen some claims that optimized PEG parsers in general cannot be faster than
Passing one class/struct vs passing several parameters I am wondering about performance considerations. Would

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.