comparison src/video/SDL_pixels.c @ 1920:8a162bfdc838

Convert SDL_malloc to SDL_calloc if appropriate, slightly faster on operating systems which map the zero page for memory allocations. OpenGL renderer in progress
author Sam Lantinga <slouken@libsdl.org>
date Sat, 22 Jul 2006 08:33:18 +0000
parents c121d94672cb
children a788656ca29a
comparison
equal deleted inserted replaced
1919:00816063b9c9 1920:8a162bfdc838
344 { 344 {
345 SDL_PixelFormat *format; 345 SDL_PixelFormat *format;
346 Uint32 mask; 346 Uint32 mask;
347 347
348 /* Allocate an empty pixel format structure */ 348 /* Allocate an empty pixel format structure */
349 format = SDL_malloc(sizeof(*format)); 349 format = SDL_calloc(1, sizeof(*format));
350 if (format == NULL) { 350 if (format == NULL) {
351 SDL_OutOfMemory(); 351 SDL_OutOfMemory();
352 return (NULL); 352 return (NULL);
353 } 353 }
354 SDL_memset(format, 0, sizeof(*format));
355 format->alpha = SDL_ALPHA_OPAQUE; 354 format->alpha = SDL_ALPHA_OPAQUE;
356 355
357 /* Set up the format */ 356 /* Set up the format */
358 format->BitsPerPixel = bpp; 357 format->BitsPerPixel = bpp;
359 format->BytesPerPixel = (bpp + 7) / 8; 358 format->BytesPerPixel = (bpp + 7) / 8;
712 SDL_AllocBlitMap(void) 711 SDL_AllocBlitMap(void)
713 { 712 {
714 SDL_BlitMap *map; 713 SDL_BlitMap *map;
715 714
716 /* Allocate the empty map */ 715 /* Allocate the empty map */
717 map = (SDL_BlitMap *) SDL_malloc(sizeof(*map)); 716 map = (SDL_BlitMap *) SDL_calloc(1, sizeof(*map));
718 if (map == NULL) { 717 if (map == NULL) {
719 SDL_OutOfMemory(); 718 SDL_OutOfMemory();
720 return (NULL); 719 return (NULL);
721 } 720 }
722 SDL_memset(map, 0, sizeof(*map));
723 721
724 /* Allocate the software blit data */ 722 /* Allocate the software blit data */
725 map->sw_data = 723 map->sw_data =
726 (struct private_swaccel *) SDL_malloc(sizeof(*map->sw_data)); 724 (struct private_swaccel *) SDL_calloc(1, sizeof(*map->sw_data));
727 if (map->sw_data == NULL) { 725 if (map->sw_data == NULL) {
728 SDL_FreeBlitMap(map); 726 SDL_FreeBlitMap(map);
729 SDL_OutOfMemory(); 727 SDL_OutOfMemory();
730 return (NULL); 728 return (NULL);
731 } 729 }
732 SDL_memset(map->sw_data, 0, sizeof(*map->sw_data));
733 730
734 /* It's ready to go */ 731 /* It's ready to go */
735 return (map); 732 return (map);
736 } 733 }
737 734