2019.10.29_revised.pdf - Quote of the Day ‣"I have always wished for my computer to be as easy to use as my telephone my wish has come true because I

2019.10.29_revised.pdf - Quote of the Day ‣"I have always...

This preview shows page 1 - 13 out of 45 pages.

"I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone." Bjarne Stroustrup Quote of the Day 1
Image of page 1
Announcements selected answers to lab questions •answers posted to questions that frequently caused difficulty •send an email if you need an answer that has not been posted Assignment 3 •change in description of one datatype •get started! loss of lecture 2
Image of page 2
Announcements Student Learning Services •series of events for students •example: "Improving Your Academic Success with the Five-Step Study Cycle" - 12:30 - 13:20 Wednesday, October 30 Murray Library 102 •more information at eventsRegistration/public/viewCurrentMonth? currentSystemId=1 3
Image of page 3
Quick review … 4
Image of page 4
malloc() form: (void *)malloc( size_t size ) allocates size bytes of contiguous memory •returns a pointer to the allocated memory that must be typecast to the correct type •memory is not cleared or initialized (fast) need header file <stdlib.h> - how do we know? 5
Image of page 5
malloc() recall type casting : a forced type conversion •overriding variable typing known to the compiler •e.g. int *buf; ... buf = (int *)malloc( BUFSIZE ); 6
Image of page 6
free() don’t need the memory anymore? •return it to the memory pool form: free( memPtr ) memPtr must point to memory allocated by the O/S using malloc() -family function •e.g. no-op if memPtr is NULL 7 int *iArray = NULL; ... iArray = (int *)calloc( 100, sizeof( int ) ); ... free( iArray );
Image of page 7
Memory Initialization already saw strcpy() , strncpy() •latter to avoid potential overflow recall: (char *)strcpy( char *dstStr, const char *srcStr ) copy the string pointed to by srcStr to the memory area pointed to by dstStr , terminating at a null byte " const " indicates that the function won't change srcStr 8
Image of page 8
Memory Initialization recall: (char *)strncpy( char *dstStr, const char *srcStr, size_t n ) copy the string pointed to by srcStr to the memory area pointed to by dstStr , terminating at a null byte or until n bytes have been copied 9
Image of page 9
Material skipped last day … 10
Image of page 10
Memory Initialization form: (void *)memset( void *startPtr, int iValue, size_t n ) set the n bytes starting at memory location addressed by startPtr to the value iValue •highly optimized bulk initialization routine - follow malloc() - use to re-initialize memory already allocated 11
Image of page 11
Memory Initialization highlights of example_47.c and example_47_log.txt : •initialization was byte level err(3) - library calls and kernel calls set global variable errno to a value after an error occurs - use err(3) to produce error message appropriate for errno - exits with status set to first arg
Image of page 12
Image of page 13

You've reached the end of your free preview.

Want to read all 45 pages?

  • Spring '14

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask You can ask ( soon) You can ask (will expire )
Answers in as fast as 15 minutes