Click here to Skip to main content
15,914,222 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Help wanted with Windows Sockets Pin
cgb1438-Dec-05 3:32
cgb1438-Dec-05 3:32 
GeneralRe: Help wanted with Windows Sockets Pin
Moak11-Dec-05 23:09
Moak11-Dec-05 23:09 
AnswerRe: Help wanted with Windows Sockets Pin
Jörgen Sigvardsson7-Dec-05 12:03
Jörgen Sigvardsson7-Dec-05 12:03 
GeneralRe: Help wanted with Windows Sockets Pin
cgb1438-Dec-05 3:43
cgb1438-Dec-05 3:43 
GeneralRe: Help wanted with Windows Sockets Pin
Jörgen Sigvardsson8-Dec-05 4:40
Jörgen Sigvardsson8-Dec-05 4:40 
QuestionHow to resize a dynamic array??? Pin
Ming Luo7-Dec-05 10:52
Ming Luo7-Dec-05 10:52 
AnswerRe: How to resize a dynamic array??? Pin
Jörgen Sigvardsson7-Dec-05 11:56
Jörgen Sigvardsson7-Dec-05 11:56 
GeneralRe: How to resize a dynamic array??? Pin
Matt Godbolt7-Dec-05 12:07
Matt Godbolt7-Dec-05 12:07 
In addition to the uninitialised variable, realloc may (and often does) return a new pointer, if the block of memory moved. If it fails, then it returns 0. A safe way of reallocating would be:
VERTEX_BUFFER *new_buffer = (VERTEX_BUFFER *)realloc(vertex_list, (sizeof(VERTEX_BUFFER)) * (++vertex_index));<br />
if (new_buffer){<br />
    // We successfully reallocated new memory, possibly moving our data to a new block, take note<br />
    // of the new address<br />
    vertex_list = new_buffer;<br />
}else{<br />
    // There was an error!  Report to the user, and note that the block at vertex_list is still<br />
    // pointing at the previously-allocated data, and must be freed!<br />
...<br />
}<br />

Note that because it may shift blocks around in memory, realloc can be a very slow function to call. Usually in this case it's customary to double the size of the allocation each time - it can be proved that over time the amortised cost of realloc tends to O(1) with the doubling approach, though it does mean you allocate a lot of memory. The STL containers (std::vector etc) do this as far as I can tell. Might be worth looking into using an STL container for your code too; it's usually pretty good at this kind of thing.

Matt Godbolt
Engineer, ProFactor Software
StyleManager project
GeneralRe: How to resize a dynamic array??? Pin
Jörgen Sigvardsson8-Dec-05 1:25
Jörgen Sigvardsson8-Dec-05 1:25 
QuestionWindows Start/Boot time Pin
Inocentric7-Dec-05 10:38
Inocentric7-Dec-05 10:38 
QuestionCfileDialog file filtering Pin
Crislen7-Dec-05 9:27
Crislen7-Dec-05 9:27 
AnswerRe: CfileDialog file filtering Pin
David Crow7-Dec-05 9:55
David Crow7-Dec-05 9:55 
QuestionUsing SQLXML, Bulk Insert XML with IDENTITY Column ... Pin
cmacgowan7-Dec-05 8:48
cmacgowan7-Dec-05 8:48 
AnswerRe: Using SQLXML, Bulk Insert XML with IDENTITY Column ... Pin
cmacgowan7-Dec-05 8:52
cmacgowan7-Dec-05 8:52 
Question[Message Deleted] Pin
NET_GEEK7-Dec-05 8:44
NET_GEEK7-Dec-05 8:44 
AnswerRe: Classic visual C++ and Visual C++.net Pin
Nish Nishant7-Dec-05 8:50
sitebuilderNish Nishant7-Dec-05 8:50 
QuestionMy dialog's close button not working? Pin
G Haranadh7-Dec-05 7:56
G Haranadh7-Dec-05 7:56 
AnswerRe: My dialog's close button not working? Pin
Shay Harel7-Dec-05 8:21
Shay Harel7-Dec-05 8:21 
GeneralRe: My dialog's close button not working? Pin
G Haranadh7-Dec-05 8:40
G Haranadh7-Dec-05 8:40 
QuestionRe: My dialog's close button not working? Pin
David Crow7-Dec-05 9:06
David Crow7-Dec-05 9:06 
AnswerRe: My dialog's close button not working? Pin
G Haranadh7-Dec-05 18:23
G Haranadh7-Dec-05 18:23 
AnswerRe: My dialog's close button not working? Pin
Nish Nishant7-Dec-05 8:51
sitebuilderNish Nishant7-Dec-05 8:51 
GeneralRe: My dialog's close button not working? Pin
G Haranadh7-Dec-05 18:29
G Haranadh7-Dec-05 18:29 
QuestionApplication's Icon Pin
Shay Harel7-Dec-05 7:36
Shay Harel7-Dec-05 7:36 
AnswerRe: Application's Icon Pin
toxcct7-Dec-05 7:42
toxcct7-Dec-05 7:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.