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

  • Home
  • SEARCH
  • 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 7129345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:13:58+00:00 2026-05-28T11:13:58+00:00

Visual C++, Microsoft Visual Studio 2010 Express: Access from this malloc works: float* block

  • 0

Visual C++, Microsoft Visual Studio 2010 Express:

Access from this malloc works:

float* block  = (float *)_aligned_malloc(32 * sizeof(float), CACHE_ALIGNMENT);
block[0] = (float)30;  // I work fine.

But when it is inside this class, it does not work:

class Test
{
    private:
        //static const int numberOfElements = 1024;

    public:
        float* block1;
        float* block2;

    // Constructor
        Test::Test(int nElements)
        {
            float* block1 = (float *)_aligned_malloc(nElements * sizeof(float), CACHE_ALIGNMENT);
            float* block2 = (float *)_aligned_malloc(nElements * sizeof(float), CACHE_ALIGNMENT);
        }
    // Destructor
        Test::~Test(void) 
        {
            _aligned_free(block1);
            _aligned_free(block2);
        }
};

...

Test testClass = Test(32); 
testClass.block1[0] = (float)30;  // Access violation!

...

Or if declared as a pointer, the same thing (this is how I first tried it):

Test* testClass = new Test(32);
testClass.block1[0] = (float)30;  // Access violation!

What am I doing wrong in terms of accessing the values when the float* is define inside a class? Is the problem something else?

  • 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-05-28T11:13:59+00:00Added an answer on May 28, 2026 at 11:13 am

    You assign to the variables local to constructor, not member variables. Try something like

        Test::Test(int nElements)
        {
            block1 = (float *)_aligned_malloc(nElements * sizeof(float), CACHE_ALIGNMENT);
            block2 = (float *)_aligned_malloc(nElements * sizeof(float), CACHE_ALIGNMENT);
        }
    

    and check the values to make sure allocation succeeded.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Taken from Exercise 1: Creating Windows Phone Applications with Microsoft Visual Studio 2010 Express
Installed Visual Studio Web Developer 2010 Express from the ISO available from this page:
Using Microsoft Visual Studio 2010: Can I write this type of macro in C?
I downloaded the Microsoft Visual Studio 2010 Express for Windows Phone and I wrote
I am using Microsoft Visual C# 2010 Express. I did not have access to
I'm using Microsoft Visual Studio 2010 Express: the C++ and VB versions. There is
From Visual Studio 2010 I can connect to my SQL Server Express 2005 instance
Platform used : Microsoft Visual Studio 2010 (C#) Database : SQL Server 2008 R2
Using: Microsoft SQL Server 2008 Microsoft Visual Studio 2010 C# .NET 4.0 WinForms Ok
How to connect with MySQL from Visual C++ Microsoft Visual Studio 2008 ? I

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.