Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / July 2004

Tip: Looking for answers? Try searching our database.

malloc in .net..

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sadun Sevingen - 18 Jul 2004 12:56 GMT
hi is there malloc command for native arrays to enlarge size of the array
???
William DePalo [MVP VC++] - 18 Jul 2004 15:33 GMT
> hi is there malloc command for native arrays to enlarge size of the array

Native arrays? If so, check the docs for the meaning of realloc()?

Regards,
Will
Sadun Sevingen - 18 Jul 2004 16:17 GMT
#include "stdafx.h"
#using <mscorlib.dll>

using namespace System;

int main(void)
{
    int dizi[10];

    for(int i = 0; i < 10; i++)
         dizi[i] = i * 2;

    size_t size = sizeof(dizi)/sizeof(dizi[0]);

    for(size_t i = 0; i < size; i++)
         Console::WriteLine(dizi[i]);

    // free(dizi); doesn't work...
    // also i want to enlarge the array

    return 0;
}
Sadun Sevingen - 18 Jul 2004 16:36 GMT
#include "stdafx.h"
#include "stdio.h"
#include "stdlib.h"
#using <mscorlib.dll>

using namespace System;

int main() {
 int number;
 int *ptr;
 int i;

 printf("How many ints would you like store? ");
 scanf("%d", &number);

 ptr = (int *)(malloc(number*sizeof(int))); /* allocate memory */

 if(ptr!=NULL) {
   for(i=0 ; i<number ; i++) {
     *(ptr+i) = i;
   }

   for(i=number ; i>0 ; i--) {
     printf("%d\n", *(ptr+(i-1))); /* print out in reverse order */
   }

   free(ptr); /* free allocated memory */
   return 0;
 }
 else {
   printf("\nMemory allocation failed - not enough memory.\n");
   return 1;
 }
}
William DePalo [MVP VC++] - 19 Jul 2004 17:45 GMT
> #include "stdafx.h"
> #include "stdio.h"
[quoted text clipped - 6 lines]
> ....
> }

Is there a question here or is this homework? <g>

Regards,
Will
Sadun Sevingen - 21 Jul 2004 11:59 GMT
it was just a question that i was seeking for all kind of arrays that can i
use on VC++.net

i found
native arrays (value type, ref type)
system array called as managed array System:Array ther are ref type
and collections inherits from Array but much more efficient by indexing
functionalty "associativety"

but i don't have any idea about vectors i'ill look @ them...
William DePalo [MVP VC++] - 19 Jul 2004 17:44 GMT
> int main(void)
> {
>      int dizi[10];
> ...
>      // free(dizi); doesn't work...

It shouldn't as dizi is on the stack. The compiler effectively creates the
code to reclaim the memory for this object in the "epilog" code that it adds
to the function at its closing brace ( "}" )

Regards,
Will
Julie - 19 Jul 2004 18:09 GMT
> #include "stdafx.h"
> #using <mscorlib.dll>
[quoted text clipped - 16 lines]
>      // also i want to enlarge the array
> ...

Yikes!

Look at std::vector instead, and get a good & current C++ programming book.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.