pebble
  • Tutorials
  • Get the SDK
  • Guides
  • Documentation
  • Examples
  • Community
  • Blog
  • More
Privacy
Cookies
Publish

Pebble C API

  • Pebble C API
  • Pebble JavaScript API
  • PebbleKit JS
  • PebbleKit iOS
  • PebbleKit Android
  • Foundation
    • App
    • App Communication
    • App Glance
    • AppMessage
    • AppSync
    • AppWorker
    • DataLogging
    • DataStructures
      • UUID
    • Dictation
    • Dictionary
    • Event Service
      • AccelerometerService
      • AppFocusService
      • BatteryStateService
      • CompassService
      • ConnectionService
      • HealthService
      • TickTimerService
    • Exit Reason
    • Internationalization
    • Launch Reason
    • Logging
    • Math
    • Memory Management
    • Platform
    • Resources
      • File Formats
    • Storage
    • Timer
    • Wakeup
    • Wall Time
    • WatchInfo
    • Rocky
  • Graphics
    • Draw Commands
    • Drawing Paths
    • Drawing Primitives
    • Drawing Text
    • Fonts
    • Graphics Context
    • Graphics Types
      • Color Definitions
  • User Interface
    • Animation
      • PropertyAnimation
    • Clicks
    • Layers
      • ActionBarLayer
      • BitmapLayer
      • MenuLayer
      • RotBitmapLayer
      • ScrollLayer
      • SimpleMenuLayer
      • StatusBarLayer
      • TextLayer
    • Light
    • Preferences
    • UnobstructedArea
    • Vibes
    • Window
      • ActionMenu
      • NumberWindow
    • Window Stack
  • Standard C
    • Format
    • Locale
    • Math
    • Memory
    • String
    • Time

Memory

Standard memory functions.

Function Documentation

void * malloc(size_t size)

Allocates a requested amount of memory.

Parameters

size

The number of bytes to allocate

Returns

A pointer to the allocated memory or NULL on error.

void * calloc(size_t count, size_t size)

Allocates space for count objects that are size bytes and fills the memory with bytes of value 0.

Parameters

count

The number of objects to allocate space for

size

The size of the object type being allocated

Returns

A pointer to the allocated memory or NULL on error.

void * realloc(void * ptr, size_t size)

Takes the memory allocated at ptr and changes the length of its allocation to the size specified.

Copies the smaller of the length of the original allocation or the new size into the newly allocated buffer.

Parameters

ptr

The memory allocation to be changed

size

The size to change the ptr allocation to

Returns

A pointer to the new allocated memory or NULL on error

void free(void * ptr)

Frees previously allocated memory.

Parameters

ptr

The memory buffer to free.

int memcmp(const void * ptr1, const void * ptr2, size_t n)

Compares the first n bytes of memory regions ptr1 and ptr2.

Parameters

ptr1

The pointer to the first memory region to compare

ptr2

The pointer to the second memory region to compare

n

The number of bytes to compare

Returns

0 if the first n bytes of ptr1 and ptr 2 match. Otherwise, the sign is determined by the sign of the difference between the first pair of bytes that differ in ptr1 and ptr2.

void * memcpy(void * dest, const void * src, size_t n)

Copies n bytes from src to dest.

Parameters

dest

The pointer to the destination memory region

src

The pointer to the source memory region

n

The number of bytes to copy

void * memmove(void * dest, const void * src, size_t n)

Copies n bytes from src to dest by first copying to a temporary area first, allowing dest and src to potentially overlap.

This can be used to move data to a location that overlaps its previous location.

Parameters

dest

The pointer to the destination memory region

src

The pointer to the source memory region

n

The number of bytes to copy

void * memset(void * dest, int c, size_t n)

Sets n bytes to c starting at dest.

This can be used to clear a memory region for example if c is 0.

Parameters

dest

The pointer to the destination memory region

c

The integer used as an unsigned char to assign to each byte

n

The number of bytes to set

Typedef Documentation

typedef unsigned int size_t

size as an unsigned integer

Need some help?

Functions

  • malloc
  • calloc
  • realloc
  • free
  • memcmp
  • memcpy
  • memmove
  • memset

Typedefs

  • size_t

Getting Help

Do you have questions about the Pebble SDK?

Do you need some help understanding something on this page?

You can either take advantage of our awesome developer community and check out the SDK Help forums, or you can send us a message through the website!