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 538869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:04:36+00:00 2026-05-13T10:04:36+00:00

CUSTOMVERTEX* pVertexArray; if( FAILED( m_pVB->Lock( 0, 0, (void**)&pVertexArray, 0 ) ) ) { return

  • 0
CUSTOMVERTEX* pVertexArray;

if( FAILED( m_pVB->Lock( 0, 0, (void**)&pVertexArray, 0 ) ) ) {
    return E_FAIL;
}


pVertexArray[0].position = D3DXVECTOR3(-1.0, -1.0,  1.0);
pVertexArray[1].position = D3DXVECTOR3(-1.0,  1.0,  1.0);
pVertexArray[2].position = D3DXVECTOR3( 1.0, -1.0,  1.0);
...

I’ve not touched C++ for a while – hence the topic but this bit of code is confusing myself. After the m_pVB->Lock is called the array is initialized.

This is great and all but the problem I’m having is how this happens. The code underneath uses nine elements, but another function (pretty much copy/paste) of the code I’m working with only access say four elements.

CUSTOMVERTEX is a struct, but I was under the impression that this matters not and that an array of structs/objects need to be initialized to a fixed size.

Can anyone clear this up?

Edit:

Given the replies, how does it know that I require nine elements in the array, or four etc…?

So as long as the buffer is big enough, the elements are legal. If so, this code is setting the buffer size if I’m not mistaken.

if( FAILED( m_pd3dDevice->CreateVertexBuffer( vertexCount * sizeof(CUSTOMVERTEX), 0, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &m_pVB, NULL ) ) ) {
        return E_FAIL;
}
  • 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-13T10:04:36+00:00Added an answer on May 13, 2026 at 10:04 am

    m_pVB points to a graphics object, in this case presumably a vertex buffer. The data held by this object will not generally be in CPU-accessible memory – it may be held in onboard RAM of your graphics hardware or not allocated at all; and it may be in use by the GPU at any particular time; so if you want to read from it or write to it, you need to tell your graphics subsystem this, and that’s what the Lock() function does – synchronise with the GPU, ensure there is a buffer in main memory big enough for the data and it contains the data you expect at this time from the CPU’s point of view, and return to you the pointer to that main memory. There will need to be a corresponding Unlock() call to tell the GPU that you are done reading / mutating the object.

    To answer your question about how the size of the buffer is determined, look at where the vertex buffer is being constructed – you should see a description of the vertex format and an element count being passed to the function that creates it.

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

Sidebar

Ask A Question

Stats

  • Questions 310k
  • Answers 310k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I like jQuery 1.4: clean, concise, chainable, includes pretty much… May 13, 2026 at 10:14 pm
  • Editorial Team
    Editorial Team added an answer In my experience a typical search query doesn't generally map… May 13, 2026 at 10:14 pm
  • Editorial Team
    Editorial Team added an answer Using PredicateBuilder (from the authors of LinqPad) you can build… May 13, 2026 at 10:14 pm

Related Questions

I am new to DirectX and I am trying to draw two rectangles in
It came up again today how to handle allowing users to add custom fields

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.